The use of role-based identity forms validation in asp.net is roughly divided into four steps

Source: Internet
Author: User
Tags config http cookie ticket client
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>



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.