Skip to content

Instantly share code, notes, and snippets.

@Dynyx
Created June 4, 2012 13:33
Show Gist options
  • Save Dynyx/2868405 to your computer and use it in GitHub Desktop.
Save Dynyx/2868405 to your computer and use it in GitHub Desktop.
Global.asax handle Application_AuthenticateRequest
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
if (HttpContext.Current.User == null) return;
if (!HttpContext.Current.User.Identity.IsAuthenticated) return;
var id = HttpContext.Current.User.Identity as FormsIdentity;
if (id == null) return;
FormsAuthenticationTicket ticket = id.Ticket;
string userData = ticket.UserData;
string[] roles = userData.Split(',');
HttpContext.Current.User = new GenericPrincipal(id, roles);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment