Hi,
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?