/// <summary> /// 保存Cookie信息,并得到ID /// 注意,这里不能使用事务锁 /// </summary> /// <param name="session"></param> /// <returns></returns> public JsonReturn SaveCookie(Guid CookieID, string CookieName, string CookieValue, DateTime ExpireTime) { DateTime today = DateTime.Now; if (ExpireTime < today) { return(JsonReturn.RunFail("无法存储Cookie信息:该Cookie已失效")); } //先检测是否存在该CookieID if (CookieID != Guid.Empty) //当前该Cookie还保存,可能是存放的另外一个 { //删除现有保存的Cookie db.ExecuteCommand(string.Format("delete from TSys_LoginUserCookie where CookieID='{0}'", CookieID)); } else { CookieID = Guid.NewGuid();//创建一个新的CookieID,用于标识该Cookie } try { DynamicObj Cookie = new DynamicObj(); Cookie.Set("CookieID", CookieID); Cookie.Set("UserInfoEntity", CookieValue); Cookie.Set("Expires", ExpireTime); Cookie.Set("CookieName", CookieName); Cookie.Set("ReadTime", DateTime.Now); //仅为单表,暂不进行事务处理 if (db.SaveNewObject(Cookie, "TSys_LoginUserCookie")) { return(JsonReturn.RunSuccess(CookieID)); } else { return(JsonReturn.RunFail("无法存储Cookie信息")); } } catch { return(JsonReturn.RunFail("存储Cookie信息时出现异常")); } }
/// <summary> /// 将指定对象类型转为 /// </summary> /// <param name="type"></param> /// <returns></returns> public static DynamicObj GetObjectPropertys(Type type) { DynamicObj obj = new DynamicObj(); PropertyInfo[] ps = type.GetProperties(); foreach (PropertyInfo p in ps) { obj.Set(p.Name, p); } return(obj); }
public void SetUserSession(string SessionID, IUserSession <T> session) { string key = $"{Options.SessionCookieName}_{SessionID}"; if (Options.IsSqlSaveCookie) { WebHelper.Current.Session.Set(key, session); } else { UserSessions.Set(key, session); } }
/// <summary> /// 在进行get之前设置参数 /// </summary> /// <param name="Key"></param> /// <param name="s"></param> public static void SetGetUrlParams(string Key, object s) { DynamicObj curParams = UrlGetSession[Current.Session.Id]; curParams.Set(Key, s); }