手机
当前位置:查字典教程网 >编程开发 >C#教程 >C#程序中session的基本设置示例及清除session的方法
C#程序中session的基本设置示例及清除session的方法
摘要:session的基本设置:usingSystem;usingSystem.Collections.Generic;usingSystem.T...

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 //清除某个Session Session["UserName"] = null; Session.Remove("UserName");

【C#程序中session的基本设置示例及清除session的方法】相关文章:

关于C#.net winform程序验证moss的集成身份认证实例

C#访问应用程序配置文件的方法

c#生成缩略图的实现方法

C# 设置系统日期格式的方法

C#保存图片到数据库并读取显示图片的方法

C#编程实现Excel文档中搜索文本内容的方法及思路

C#中Array与ArrayList用法及转换的方法

C# byte数组与Image相互转换的方法

使用@符号让C#中的保留字做变量名的方法详解

C#.NET字符串比较中忽略符号的方法

精品推荐
分类导航