ASP.NET除去会话中的项目? [英] ASP.NET removing an item from Session?

查看:106
本文介绍了ASP.NET除去会话中的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪种方法preferred?

  Session.Remove(富);

会话[富] = NULL;
 

时有区别吗?

解决方案
  

时有区别吗?

有。 Session.Remove(键)删除条目(包括键和放大器;值)从字典,而会话[关键] = NULL 分配一个值(这恰好是空),以一个关键。前者通话结束后,这个密钥不会出现在会话#键集合。但在后者,关键仍然可以在领取钥匙找到。

Which method is preferred?

Session.Remove("foo");

Session["foo"] = null;

Is there a difference?

解决方案

Is there a difference?

There is. Session.Remove(key) deletes the entry (both key & value) from the dictionary while Session[key] = null assigns a value (which happens to be null) to a key. After the former call, the key won't appear in the Session#Keys collection. But after the latter, the key can still be found in the key collection.

这篇关于ASP.NET除去会话中的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆