Autorisierung in ASP.NET MVC 2 mit web.config-Datei


Ich habe eine ASP.MVC 2 web Seite, und ich habe meine Authentifizierung wie folgt vorgenommen:

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);  

Nun würde ich gerne meine web.config in einer Weise, dass nur wenige Seiten, die nur zugänglich, wenn ein Benutzer authentifiziert ist. Ich habe meine web.config-set:

<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>  

... aber das nicht Arbeit.

Was mache ich falsch?

InformationsquelleAutor dani | 2010-10-06
Schreibe einen Kommentar