有没有人知道如何从Forms Authentication Ticket向HTTPContext添加通用主体?
答案 0 :(得分:3)
您可以在Application_AuthenticateRequest
事件中执行此操作。 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);
}