.NET FormsAuthentication身份validation票证的通用主体

有谁知道如何从Forms Authentication Ticket向HTTPContext添加通用主体?

您可以在Application_AuthenticateRequest事件中执行此操作。 这是一个例子 :

 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); }