惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

IT之家
IT之家
A
About on SuperTechFans
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
N
Netflix TechBlog - Medium
Microsoft Security Blog
Microsoft Security Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
博客园 - 聂微东
博客园 - Franky
D
Docker
Martin Fowler
Martin Fowler
Engineering at Meta
Engineering at Meta
The Cloudflare Blog
人人都是产品经理
人人都是产品经理
Last Week in AI
Last Week in AI
U
Unit 42
F
Fortinet All Blogs
H
Help Net Security
Blog — PlanetScale
Blog — PlanetScale
Microsoft Azure Blog
Microsoft Azure Blog
罗磊的独立博客
P
Proofpoint News Feed
月光博客
月光博客
G
Google Developers Blog

博客园 - stu_acer

对C#对象的Shallow、Deep Cloning认识【转】 PowerShell 启动应用程序【转】 把boolean 参数放到最后面(Put boolean arguments last)【转载】 几个收藏的根据数据库生成Insert语句的存储过程[修正版] SQL Server删除外键约束 IE6下PNG图片透明显示解决方法(From QQ) 用Regex类计算一个字符串出现次数是最好方法【转载】 DataList绑定数据到泛型类(Dictionary) 【转】 重写Asp.NET2.0 TreeView的折叠/展开方法(TreeView_ToggleNode) javascript window.close() 去掉那讨厌的确认对话框【转】 thickbox使用技巧【转】 - stu_acer - 博客园 jQuery操作checkbox的例子(全选,反选,获取选取值)【转】 查看SQL Server 2005版本号 创建SQL索引,查看SQL性能语句收集 ddlevelsmenu在IE6下,与select冲突的解决办法【整理】 IE6 Select元素无法被div等元素覆盖的bug解决办法【zz】 利用Attribute和反射从模板生成短信 - stu_acer - 博客园 Session & Cookie 的使用建议(zz) - stu_acer AdventureWorks、Northwind、pubs示例数据库下载
C#有关Session 操作的几个误区【转】 - stu_acer - 博客园
stu_acer · 2009-12-14 · via 博客园 - stu_acer

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.asax Session_Start 事件被触发。你还可以使用 this.Session.IsNewSession 属性来判断当前 Session 是否重新创建的。
由于某些组件和控件可能要使用 Session 信息(如使用 this.Session.SyncRoot 进行同步),因此不要轻易使用该方法清理 Session。

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

原文链接:http://www.cnblogs.com/X-Jonney/archive/2009/03/19/1416699.html