国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#程序中session的基本設置示例及清除session的方法

2019-10-29 21:30:15
字體:
來源:轉載
供稿:網友
這篇文章主要介紹了C#程序中session的基本設置示例及清除session的方法,是C#入門學習中的基礎知識,需要的朋友可以參考下
 

session的基本設置:

using System;using System.Collections.Generic;using System.Text;using System.Web;using System.Web.SessionState;namespace OAFrameWork{  public class CSession  {      public static object Get(string Key)    {      return HttpContext.Current.Session[Key];    }  public static string GetString(string Key)    {      object obj = HttpContext.Current.Session[Key];      if (obj == null) return "";      else return obj.ToString();    }    public static object Get(string Key,object DefaultValue)    {      if (HttpContext.Current.Session[Key] == null)        return DefaultValue;      else        return HttpContext.Current.Session[Key];    }    public static object Get(string Key, object DefaultValue,Boolean CanAdd)    {      if (HttpContext.Current.Session[Key] == null)      {        if(CanAdd==true)          HttpContext.Current.Session.Add(Key, DefaultValue);        return DefaultValue;      }      else        return HttpContext.Current.Session[Key];    }    public static Boolean Set(string Key,object Value)    {      try      {        if (Value == null && HttpContext.Current.Session[Key] != null)        {          HttpContext.Current.Session.Remove(Key);        }        else if (HttpContext.Current.Session[Key] == null)          {            HttpContext.Current.Session.Add(Key, Value);          }          else          {            HttpContext.Current.Session[Key] = Value;          }        return true;      }      catch (Exception ex)      {        CMsgBox.Show(ex.Message);         return false;      }    }             }}

清除Session:

Session.Abandon();//清除全部Session//清除某個SessionSession["UserName"] = null;Session.Remove("UserName");


注:相關教程知識閱讀請移步到c#教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 威宁| 布尔津县| 白朗县| 天全县| 嫩江县| 江西省| 富民县| 商丘市| 论坛| 内乡县| 醴陵市| 合阳县| 高雄市| 珲春市| 连平县| 竹山县| 文成县| 永吉县| 吉隆县| 灌阳县| 宁都县| 新乐市| 昌邑市| 合作市| 淳安县| 泸州市| 深圳市| 青田县| 六枝特区| 宜兰县| 三穗县| 夹江县| 瑞昌市| 顺义区| 钟山县| 西城区| 遂溪县| 西林县| 武鸣县| 玛纳斯县| 定陶县|