Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1928924
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T07:04:42+00:00 2026-05-17T07:04:42+00:00

I have an ASP.MVC 2 web page and I have my authentication done like

  • 0

I have an ASP.MVC 2 web page and I have my authentication done like this:

FormsAuthentication.SetAuthCookie(user.UserName, false);
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, "fooPage" + user.UserName, DateTime.Now, DateTime.Now.AddMinutes(10), false, String.Empty);

HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(authTicket));
Response.Cookies.Add(cookie);  

Now I would like to set my web.config in a way that few pages can be only accessed if a user is authenticated. I have my web.config set like this:

<configuration>  
  <system.web>  
    <authentication mode="Forms">  
      <forms loginUrl="~/Account/LogIn" timeout="2880"/> //all users can access my web site  
    </authentication>  
    <authorization>  
      <allow users="*"/>  
    </authorization>  
  </system.web>  
  <location path="~/Views/Sales/Index.aspx">  
    <system.web>  
      <authorization>  
        <deny users="?"/> //only authenticated users can access this page  
      </authorization>  
    </system.web>  
  </location>  
</configuration>  

… but this does not work.

What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T07:04:48+00:00Added an answer on May 17, 2026 at 7:04 am

    It’s much easier to put the [Authorize] attribute on the controller action:

    public class SalesController : Controller
    {
        [Authorize]
        public ActionResult Index()
        { 
            // etc
    

    You can also put the attribute on the controller instead of having to put it on every action method…

    Edit in response to your comment: I don’t know that it’s possible to do natively using XML, but check out http://www.jigar.net/articles/viewhtmlcontent324.aspx

    Second edit, I’ve done some research and testing, and it is possible to use the default ASP.NET web.config stuff, use <location path="~/Sales/Index"> instead of <location path="~/Views/Sales/Index.aspx">

    BUT

    you have to be really really careful if there’s more than one URL that could land you on the same page, such as /, /Home, /Home/, /Home/Index, etc – you won’t get the authorization settings on all of them automatically. I think it’s much safer to use something MVC-aware, such as the [Authorize] attribute, or the custom scheme I linked to above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET web page(Not MVC ) (HomePage.aspx) and another page (PRiceList.aspx).I have
I have an ASP.NET MVC web site. I have many actions which require authentication
I have an ASP.NET MVC web page that has a file upload control. Under
I have implented some lovely forms authentication in ASP.NET MVC 3, this has been
I have a asp.net mvc web page that stores my employeeid in session state,
i have an asp.net-mvc web page and i am using jqgrid on the front
I am in a strange problem. I have an asp.net mvc web page. Scenario
I have an ASP.Net MVC web application using forms authentication. I am using OpenID
I have an ASP.NET MVC 3 web application, which I would like to publish
I have an ASP.NET MVC web app and on one page I wish to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.