C#程序中session的基本設(shè)置示例及清除session的方法
session的基本設(shè)置:
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 //清除某個Session Session["UserName"] = null; Session.Remove("UserName");
欄 目:C#教程
下一篇:C#中使用XmlDocument類來創(chuàng)建和修改XML格式的數(shù)據(jù)文件
本文標(biāo)題:C#程序中session的基本設(shè)置示例及清除session的方法
本文地址:http://mengdiqiu.com.cn/a1/C_jiaocheng/6592.html
您可能感興趣的文章
- 01-10C#通過反射獲取當(dāng)前工程中所有窗體并打開的方法
- 01-10C#實現(xiàn)Winform中打開網(wǎng)頁頁面的方法
- 01-10C#實現(xiàn)由四周向中心縮小的窗體退出特效
- 01-10Extjs4如何處理后臺json數(shù)據(jù)中日期和時間
- 01-10WinForm實現(xiàn)程序一段時間不運行自動關(guān)閉的方法
- 01-10C#中DataGridView常用操作實例小結(jié)
- 01-10C#編程獲取資源文件中圖片的方法
- 01-10C#實現(xiàn)將程序鎖定到Win7任務(wù)欄的方法
- 01-10C#使用windows服務(wù)開啟應(yīng)用程序的方法
- 01-10asp.net中XML如何做增刪改查操作


閱讀排行
本欄相關(guān)
- 01-10C#通過反射獲取當(dāng)前工程中所有窗體并
- 01-10關(guān)于ASP網(wǎng)頁無法打開的解決方案
- 01-10WinForm限制窗體不能移到屏幕外的方法
- 01-10WinForm繪制圓角的方法
- 01-10C#實現(xiàn)txt定位指定行完整實例
- 01-10WinForm實現(xiàn)仿視頻 器左下角滾動新
- 01-10C#停止線程的方法
- 01-10C#實現(xiàn)清空回收站的方法
- 01-10C#通過重寫Panel改變邊框顏色與寬度的
- 01-10C#實現(xiàn)讀取注冊表監(jiān)控當(dāng)前操作系統(tǒng)已
隨機(jī)閱讀
- 01-10使用C語言求解撲克牌的順子及n個骰子
- 08-05DEDE織夢data目錄下的sessions文件夾有什
- 04-02jquery與jsp,用jquery
- 01-10delphi制作wav文件的方法
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 08-05dedecms(織夢)副欄目數(shù)量限制代碼修改
- 08-05織夢dedecms什么時候用欄目交叉功能?
- 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置
- 01-11ajax實現(xiàn)頁面的局部加載
- 01-10C#中split用法實例總結(jié)