Ejemplo n.º 1
0
 /// <summary>
 /// 删除Session
 /// </summary>
 /// <param name="name">session的名称</param>
 /// <returns>true:删除成功,false:删除失败</returns>
 public static bool RemoveSession(SessinoName name)
 {
     if (HttpContext.Current != null && HttpContext.Current.Session != null &&
         !string.IsNullOrEmpty(Convert.ToString(HttpContext.Current.Session[name.ToString()])))
     {
         HttpContext.Current.Session[name.ToString()] = null;
     }
     return(true);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 获取session的值
 /// </summary>
 /// <typeparam name="T">泛型</typeparam>
 /// <param name="name">session的名称(枚举类型)</param>
 /// <returns></returns>
 public static T GetSession <T>(SessinoName name)
 {
     if (JudgeSession(name))
     {
         return((T)HttpContext.Current.Session[name.ToString()]);
     }
     else
     {
         return(default(T));
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 判断session是否存在
 /// </summary>
 /// <param name="name">session的名称(枚举类型)</param>
 /// <returns>true:已登陆,false:未登录</returns>
 public static bool JudgeSession(SessinoName name)
 {
     return(HttpContext.Current.Session[name.ToString()] != null &&
            !string.IsNullOrEmpty(HttpContext.Current.Session[name.ToString()].ToString()));
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 保存session方法
 /// <param name="name">session的名称(枚举类型)</param>
 /// <param name="obj">session的值</param>
 /// </summary>
 public static void SaveSession(SessinoName name, object obj)
 {
     HttpContext.Current.Session[name.ToString()] = obj;
 }