public static void SetAuthCookie(UserIdentity _user) { if (_user == null) return; double totalSeconds = 50000; // Thenn Note //int timeout = //FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, // version // _user.Name, // user name // DateTime.Now, // create time // DateTime.Now.AddSeconds(3000), // expire time // false, // persistent // _user.UserData); // user data string userData = "InCache"; FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, // version _user.Name, // user name DateTime.Now, // create time DateTime.Now.AddSeconds(totalSeconds), // expire time false, // persistent userData); // user data string strEncryptedTicket = FormsAuthentication.Encrypt(ticket); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, strEncryptedTicket); HttpContext.Current.Response.Cookies.Add(cookie); if (HttpContext.Current.Cache[_user.Name] == null) HttpContext.Current.Cache.Insert(_user.Name, _user.UserData, null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(totalSeconds)); // HttpContext.Current.Session[Cache_Authenticate] = _user.UserData;//, null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(totalSeconds)); }
void OnAuthenticate(object sender, EventArgs e) { HttpApplication app = (HttpApplication)sender; if (app.Context.User != null && app.Context.User.Identity.IsAuthenticated) { HttpCookie authenCookie = app.Context.Request.Cookies.Get(FormsAuthentication.FormsCookieName); if (authenCookie == null) return ; FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authenCookie.Value); UserIdentity Id = new UserIdentity(ticket); FanxiPrincipal _principal = new FanxiPrincipal(Id); app.Context.User = _principal; } }
public FanxiPrincipal(UserIdentity midentity) { _identity = midentity; }
public FanxiPrincipal(UserIdentity midentity) : base(midentity) { _identity = midentity; }