protected void Application_AcquireRequestState(object sender, EventArgs e) { var cookies = Context.Request.Cookies; var session = Context.Session; Principal principal = null; if (cookies[CookieHelper.AuthCookieName] != null) { var authCookieData = cookies[CookieHelper.AuthCookieName].Value; if (authCookieData != null) { try { var authCookieTicket = FormsAuthentication.Decrypt(authCookieData); if (!authCookieTicket.Expired) { var authUserData = new AuthUserData(); if (authUserData.Import(authCookieTicket.UserData)) { var isAuthenticated = false; if (session.IsNewSession || session.SessionID != authUserData.SessionId) { isAuthenticated = false; } else { isAuthenticated = true; } principal = new Principal(authUserData.UserId.ToString(), isAuthenticated) { UserId = authUserData.UserId }; } } } catch (Exception exception) { } } } Context.User = principal; }
public static AuthUserData AuthCookieData() { AuthUserData authUserData = null; if (Cookies[AuthCookieName] != null) { var authHttpCookie = Cookies[AuthCookieName].Value; var formsAuthTicket = FormsAuthentication.Decrypt(authHttpCookie); if (formsAuthTicket != null) { authUserData = new AuthUserData(); authUserData.Import(formsAuthTicket.UserData); } } return authUserData; }