Does anyo开发者_运维百科ne know how to add a generic principal to the HTTPContext from the Forms Authentication Ticket?
You could do this in the Application_AuthenticateRequest
event. Here's an example:
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
var user = HttpContext.Current.User;
if (user == null || !user.Identity.IsAuthenticated)
{
return;
}
// read the roles from the cookie and set a custom generic principal
var fi = (FormsIdentity) HttpContext.Current.User.Identity;
var fat = fi.Ticket;
var astrRoles = fat.UserData.Split('|');
HttpContext.Current.User = new GenericPrincipal(fi, astrRoles);
}
精彩评论