protected void Application_AuthenticateRequest(Object sender,EventArgs e) {
// Extract the forms authentication cookie
string cookieName = FormsAuthentication.FormsCookieName;
HttpCookie authCookie = Context.Request.Cookies[cookieName];
if(null == authCookie) {
// There is no authentication cookie.
return;
}
FormsAuthenticationTicket authTicket = null;
try {
authTicket = FormsAuthentication.Decrypt(authCookie.Value);
} catch(Exception ex) {
// Log exception details (omitted for simplicity)
return;
}
if (null == authTicket) {
// Cookie failed to decrypt.
return;
}
// When the ticket was created, the UserData property wasassigned
// a pipe delimited string of role names.
// Create an Identity object
FormsIdentity id = new FormsIdentity( authTicket );
string[] Roles =new string[2];
Roles[0]="User";
// This principal will flow throughout the request.
System.Security.Principal.GenericPrincipal principal = new System.Security.Principal.GenericPrincipal(id,Roles);
// Attach the new principal object to the current HttpContextobject
System.Web.HttpContext.Current.User = principal;
}
vendredi 6 mai 2011
Application AuthenticateRequest
Inscription à :
Publier les commentaires (Atom)
Aucun commentaire:
Enregistrer un commentaire