asp.net
The use of role-based identity forms validation in asp.net is roughly divided into four steps
1. Configure System files Web.config
<system.web>
<authentication mode= "Forms" >
<forms name= ". Yaocookies" Loginurl= "/duan/manage/login.aspx" protection= "All"
timeout= "path="/"/>
</authentication>
</system.web>
The name in the <forms> label specifies the HTTP Cookie to use for authentication. By default, the value of name is. Aspxauth. After authenticating the user in this way, a FormsAuthenticationTicket type of authentication ticket is established with the user's information, and then encrypted into a string, Finally, the string is written to the cookie of the client's name-specified name. Once this cookie is written to the client, the user who accesses the Web application again will send it along with the cookie to the server, and the server will know that the user is authenticated.
The loginurl in the <forms> label means that the unauthenticated user will automatically be directed to the path to which loginurl is pointing. If the authenticating user is valid, generate the authentication ticket that corresponds to this user, write to the client's cookie, Finally, redirect the browser to the page that the user asked for the initial interview. The System.Web.Security.FormsAuthentication.RedirectFromLoginPage () method is used to implement redirection.
<forms> the timeout and path in the label are provided with the authentication ticket written to the cookie expiration and default path
2. Create a Web.config file in a protected folder such as manage, as
<configuration>
<!--specify access rights to the entire manage directory-->
<system.web>
<authorization>
<!--multiple roles, separating-->
<allow roles= "Admin,user"/>
<deny users= "*"/>
</authorization>
</system.web>
<!--can also control permissions on a page
<location path= "Announcelist.aspx" >
<system.web>
<authorization>
<allow roles= "admin"/>
<deny users= "*"/>
</authorization>
</system.web>
</location>
<location path= "Configinfo.aspx" >
<system.web>
<authorization>
<allow roles= "Users"/>
<deny users= "*"/>
</authorization>
</system.web>
</location>
-->
</configuration>
Note: This configuration content can also be added to the system's Web.config file, and note the Add location:
........
</system.web>
<location path= "Manage/announcelist.aspx" >
<system.web>
<authorization>
<allow roles= "admin"/>
<deny users= "*"/>
</authorization>
</system.web>
</location>
</configuration>