private static void Application_AuthenticateRequest(object sender, EventArgs e) { HttpApplication application = (HttpApplication)sender; HttpContext context = application.Context; if ((context.Request.Url.ToString().IndexOf("/Install/Default.aspx", StringComparison.OrdinalIgnoreCase) < 0) && (context.Request.Url.ToString().IndexOf("/Install/Upgrade.aspx", StringComparison.OrdinalIgnoreCase) < 0)) { FormsAuthenticationTicket ticket = null; //获取用于FORM身份验证票证 string formsCookieName = FormsAuthentication.FormsCookieName; HttpCookie cookie = context.Request.Cookies[formsCookieName]; if (cookie == null) { //使用新的验证标识创建用户基本功能对象 UserPrincipal principal = new UserPrincipal(new AnonymousAuthenticateIdentity()); principal.UserInfo = new UserInfo(true); principal.UserInfo.GroupId = -2; principal.UserInfo.IsInheritGroupRole = true; PEContext.Current.User = principal; } else { try { //根据票证传递的参数而获取票证 ticket = FormsAuthentication.Decrypt(cookie.Value); } catch (ArgumentException) { return; } catch (CryptographicException) { //移除Forms验证Cookies context.Request.Cookies.Remove(formsCookieName); } if (ticket != null) { UserPrincipal principal2 = UserPrincipal.CreatePrincipal(ticket); if (principal2.Identity.IsAuthenticated) { principal2.UserInfo = Users.GetUsersByUserName(principal2.UserName); UserPurviewInfo userPurview = principal2.UserInfo.UserPurview; principal2.PurviewInfo = userPurview; PEContext.Current.User = principal2; FormsIdentity identity = new FormsIdentity(ticket); GenericPrincipal principal3 = new GenericPrincipal(identity, new string[] { principal2.RoleId.ToString(CultureInfo.CurrentCulture) }); context.User = principal3; } else { GenericPrincipal principal4 = new GenericPrincipal(new NoAuthenticateIdentity(), null); context.User = principal4; } } } } }