手机
当前位置:查字典教程网 >编程开发 >asp.net教程 >asp.net(c#)有关 Session 操作的几个误区
asp.net(c#)有关 Session 操作的几个误区
摘要:1.this.Session["username"]=nullHttpSessionState内部使用NameObjectCollectio...

1.this.Session["username"]=null

HttpSessionState内部使用NameObjectCollection类型的集合对象来存储用户数据。因此使用this.Session["username"]=null仅仅是将该元素的值设为null而已,并没有真的将其从Session中移除。(为什么?晕~~~建议看看C#基础方面的书。)

正确的方法是:this.Session.Remove("username");

删除全部数据:this.Session.RemoveAll();或this.Session.Clear();

2.this.Session.Abandon()

该方法会导致当前Session被取消,系统会触发Global.asax中的Session_End事件(仅限于Mode=InProc时)。

尽管再次发出请求时SessionID(可能)没有发生变化,但是你会发现Global.asaxSession_Start事件被触发。你还可以使用this.Session.IsNewSession属性来判断当前Session是否重新创建的。

由于某些组件和控件可能要使用Session信息(如使用this.Session.SyncRoot进行同步),因此不要轻易使用该方法清理Session。

3.用户身份验证

不要使用this.Session["username"]="ZhangSan"、if(this.Session["username"]!=null)这样的方式进行用户身份验证,这种方式既不安全也不合理。有关身份验证请参考MSDN文档或雨痕写的相关文章。

【asp.net(c#)有关 Session 操作的几个误区】相关文章:

asp.net(c#)下Jmai去说明 使用与下载

asp.net(c#) 水仙花数

asp.net 按字节检查包含全半角的文字

asp.net小孔子cms中的数据添加修改

asp.net(c#)不可访问,因为它受保护级别限制

asp.net页面防止重复提交示例

asp.net(c#)Enterprise Library 3.0 下载

asp.net UpdatePanel的简单用法

asp.net 文件上传实例汇总

asp.net(c#) MS AJAX的安装

精品推荐
分类导航