C# 删除时要使用哪种会话方法?
我一直在使用Session.clear(),我在firecookie中注意到该会话仍然存在。所以我开始在谷歌上搜索,发现有4种方法可以删除会话C# 删除时要使用哪种会话方法?,c#,.net,asp.net,C#,.net,Asp.net,我一直在使用Session.clear(),我在firecookie中注意到该会话仍然存在。所以我开始在谷歌上搜索,发现有4种方法可以删除会话 Session.Remove(strSessionName); Remove an Item from Session State Collection Session.RemoveAll() Remove all items from session collection Session.Clear() Remove all
Session.Remove(strSessionName); Remove an Item from Session State Collection
Session.RemoveAll() Remove all items from session collection
Session.Clear() Remove all items from session collection Note: There is no difference between Clear and RemoveAll. RemoveAll() calls Clear(), internally.
Session.Abandon() Cancels the Current Session
现在,clear和remove似乎做了同样的事情,但是您应该使用哪一个呢,比如为什么使用remove()而不是放弃清除
就像使用会话。放弃它会终止当前会话。其中clear()删除这些值
为什么您只想保留会话,而不包含任何值?为什么不完全杀死它呢?Session.advand()会在global.asax文件中触发Session\u End事件,而Session.Clear()不会
设想一个场景,其中存储用户的会话开始时间和结束时间用于审核目的-您可能希望偶尔清除他们的会话(例如更新配置文件设置),而不触发会话结束事件