protected void Application_PostAuthenticateRequest(Object sender, EventArgs e) { HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName]; if (authCookie != null) { try { FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value); JavaScriptSerializer serializer = new JavaScriptSerializer(); CustomPrincipalSerializeModel serializeModel = serializer.Deserialize <CustomPrincipalSerializeModel>(authTicket.UserData); if (serializeModel != null) { CustomPrincipal newUser = new CustomPrincipal(authTicket.Name); newUser.Parse(serializeModel); HttpContext.Current.User = newUser; } else { FormsAuthentication.SignOut(); Response.Redirect(FormsAuthentication.LoginUrl, true); } } catch { FormsAuthentication.SignOut(); Response.Redirect(FormsAuthentication.LoginUrl, true); } } }