开发者

.NET FormsAuthentication Generic Principal from Authentication Ticket

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜