使用Global

 protected void Application_AuthenticateRequest(object sender, EventArgs e)
    {
        if (HttpContext.Current.Request.IsAuthenticated)//判断用户是否登陆
        {
            if (Context.User.Identity.AuthenticationType == "Forms")//判断是否是Forms验证
            {
                //对cookie解密
                FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value);
                string[] role = ticket.UserData.Split(',');
                Context.User = new System.Security.Principal.GenericPrincipal(HttpContext.Current.User.Identity, role);
            }
        }

    }

posted @ 2008-08-27 08:29  booer  阅读(321)  评论(0编辑  收藏  举报