ASP.NET 从会话中删除一个项目? [英] ASP.NET removing an item from Session?

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

问题描述

首选哪种方法?

Session.Remove("foo");

Session["foo"] = null;

有区别吗?

推荐答案

有区别吗?

有.Session.Remove(key) 从字典中删除条目(键和值),而 Session[key] = null 分配一个值(恰好为空)到一个关键.在前一次调用之后,密钥将不会出现在 Session#Keys 集合中.但是在后者之后,仍然可以在密钥集合中找到密钥.

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天全站免登陆