2010-07-16 40 views
2

我一直在使用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 items from session collection Note: There is no difference between Clear and RemoveAll. RemoveAll() calls Clear(), internally. 
Session.Abandon() Cancels the Current Session 

现已明确,并删除似乎做同样的事情,但哪一个你应该可以使用像这样为什么使用remove()方法上摒弃了明确。

就像你使用session.Abandon它杀死了当前会话。 clear()将删除这些值。

为什么你只想保持会议中没有任何值呢?为什么不把它完全杀死?

回答

4

Session.Abandon()在您的global.asax文件中触发Session_End事件,而Session.Clear()不触发此事件。

想象一下,为了审计目的而存储用户的会话开始时间和结束时间的场景 - 您可能需要偶尔清除其会话(例如更新配置文件设置),而不触发Session_End事件。