But in the course of my use, I found that the control of the role is not so easy, through the Internet to find information, and finally solve the problem. The main considerations are listed below.
1, in the configuration file, the role of the allow item to be placed in the front of the deny entry, the users to configure to *, not?
Code
Copy Code code as follows:
<location path= "Doctors" >
<system.web>
<authorization>
<allow roles= "doctors"/>//This in the former
<deny users= "*"/>
</authorization>
</system.web>
</location>
2. Write the role to the bill
Code
Copy Code code as follows:
String role= "doctors";
FormsAuthenticationTicket Ticket = new FormsAuthenticationTicket (1, username, DateTime.Now, DateTime.Now.AddMinutes ( , false, role, "/");//Establish an authentication ticket object
String hashticket = Formsauthentication.encrypt (Ticket);//cryptographic Serialization verification ticket
HttpCookie Usercookie = new HttpCookie (Formsauthentication.formscookiename, Hashticket);
Generate cookies
RESPONSE.COOKIES.ADD (Usercookie);//Output cookie
Response.Redirect ("")//Redirect to initial page of user request
3, identity paper does not directly provide the role of direct support, need to be in the application_authenticaterequest to analyze
Code
Copy Code code as follows:
string[] roles = AuthTicket.UserData.Split (new char[] {' | '});
FormsIdentity id = new FormsIdentity (AuthTicket);
System.Security.Principal.GenericPrincipal Principal = new System.Security.Principal.GenericPrincipal (ID, roles);
Context.User = Principal;
Make a general understanding of these three points.
Code Packaging