protected void Application_PostAuthenticateRequest() { HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName]; if (authCookie != null) { FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value); JavaScriptSerializer js = new JavaScriptSerializer(); UserSecurityRole user = js.Deserialize <UserSecurityRole>(ticket.UserData); SecurityIdentity identity = new SecurityIdentity(user); SecurityPrinciple principle = new SecurityPrinciple(identity); HttpContext.Current.User = principle; } }
protected void Application_PostAuthenticateRequest(Object sender, EventArgs e) { HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName]; if (authCookie != null) { FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value); JavaScriptSerializer serializer = new JavaScriptSerializer(); var serializeModel = serializer.Deserialize <User>(authTicket.UserData); var newUser = new SecurityPrinciple(serializeModel); newUser.UserId = serializeModel.Id; newUser.FirstName = serializeModel.FirstName; newUser.LastName = serializeModel.LastName; HttpContext.Current.User = newUser; } }