Which Session Method to use when removing?
I been using Session.clear() and I noticed in firecookie that the session still exists. So I started to google around and found there are 4 ways to remove a session
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
Now clear and remove seem to do the same thing but which one should you be using like why use remove() over abandon over clear.
Like if you use session.Abandon it kills the current session. Where clear() removes the values.
Why would you only want to keep the session around with no values in it? Why not just kill it completely?
Session.Abandon() fires the Session_End event in your global.asax file, while Session.Clear() does not.
Imagine a scenario where you store a user's session start times and end time for auditing purposes - you may want to occasionally clear their session (updating profile settings for example), without triggering a Session_End event.
精彩评论