public static TB_USER BringUser() { Account_DBEntities AccountDB = new Account_DBEntities(); if (General.Session[Static.Session.User] == null) { if (new HttpRequestWrapper(General.Request).IsAjaxRequest()) { return(null); } HttpCookie ck = General.Request.Cookies[Static.Session.User]; if (ck == null) { return(null); } else { int ID = 0; int.TryParse(Crypto.DecryptStringAES(ck.Value, Static.Cookie.SharedSecret), out ID); if (ID <= 0) { return(null); } if (!SingleUser.CookieIdExist(ID)) { return(null); } TB_USER User = AccountDB.TB_USER.FirstOrDefault(d => d.Id == ID); if (User != null) { LoadUser(User); } else { return(null); } return(User); } } else { TB_USER User = General.Session[Static.Session.User] as TB_USER; if (!SingleUser.CookieIdExist(User.Id)) { return(null); } return(User); } }
public static void LoadUser(TB_USER User) { General.Session[Static.Session.User] = User; HttpCookie ck = General.Request.Cookies[Static.Cookie.User]; if (ck == null) { ck = new HttpCookie(Static.Cookie.User, Crypto.EncryptStringAES(User.Id.ToString(), Static.Cookie.SharedSecret)); } if (ck.Expires < DateTime.Now) { ck.Value = Crypto.EncryptStringAES(User.Id.ToString(), Static.Cookie.SharedSecret); } ck.Expires = DateTime.Now.AddDays(1); General.Response.Cookies.Add(ck); SingleUser.AddUser(User.strAccountID, User.Id); }