代码之家  ›  专栏  ›  技术社区  ›  chobo2

删除时使用哪种会话方法?

  •  2
  • chobo2  · 技术社区  · 15 年前

    我一直在使用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
    

    现在clear和remove似乎做了同样的事情,但是应该使用哪一个,比如为什么使用remove()over-discarge over clear。

    就像你使用会话一样。放弃它会杀死当前会话。where clear()删除值。

    为什么您只想让会话保持在没有值的状态?为什么不把它完全杀死?

    1 回复  |  直到 15 年前
        1
  •  4
  •   Damien Dennehy    15 年前

    session.abuse()在global.asax文件中激发session_end事件,而session.clear()则不激发。

    设想一个场景,您存储用户的会话开始时间和结束时间用于审核目的-您可能希望偶尔清除他们的会话(例如更新配置文件设置),而不触发会话结束事件。

    推荐文章