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(); AccountPrincipalSerializeModel serializeModel = serializer.Deserialize <AccountPrincipalSerializeModel>(authTicket.UserData); AccountPrincipal newUser = new AccountPrincipal(authTicket.Name); newUser.UserId = serializeModel.UserId; newUser.FirstName = serializeModel.FirstName; newUser.LastName = serializeModel.LastName; HttpContext.Current.User = newUser; } }
public static void SetByAccountId(string accountId) { var principal = new AccountPrincipal(accountId); Thread.CurrentPrincipal = principal; }