/// <summary> /// 信息是否存在 /// </summary> /// <returns></returns> public static bool IsExist <T>(this HttpSessionState session, string Key) { bool ret = false; T userInfo = session.GetValue <T>(Key); if (userInfo != null) { ret = true; } return(ret); }
/// <summary> /// Ensures a specific key to be either already in the ASP.NET session state or to be newly created /// </summary> /// <typeparam name = "T">The generic type to be returned</typeparam> /// <param name = "sessionState">The session state.</param> /// <param name = "key">The session state key.</param> /// <returns>The session state value.</returns> /// <example> /// <code> /// public List<string> StringValues { /// get { return this.Session.Ensure<List<string>>("StringValues"); } /// set { this.ViewState.Set("StringValues", value); } /// } /// </code> /// </example> public static T Ensure <T>(this HttpSessionState sessionState, string key) where T : class, new() { var value = sessionState.GetValue <T>(key); if (value == null) { value = new T(); sessionState[key] = value; } return(value); }
public static T GetValue <T>(this HttpSessionState source, Guid pageGUID, string keyContext, string keyName) { return((T)source.GetValue(pageGUID, keyContext, keyName)); }