http://www.codeproject.com/KB/aspnet/ExploringSession.aspx#21
Many many thanks to Mr. Abhijit Jana for such an informative and fantastic article.
Both Session.Clear() and Session.RemoveAll() does the same job.
"Removes All Keys and Values from the Session state collection."
Then what is the difference between these two ?
Session.RemoveAll() Calls Clear() method internally. Yes it is.
Now, what does this two methods do ?
- They removes all keys and values from the session-state collection . which means just remove the session items nothing more than that and session ID Will remain Same.
- Session.Clear() and Session.RemoveAll() never raised Session_End() . Session_End raised by Session.abandon() and if we are not explicitly calling the Abandon(), then Session_End will fire on SessionTimeOut.
- Abandon method destroys all the objects stored in a Session object and releases their resources. Once you call this method, Session_End will raised automatically.
- When you abandon a session, the session ID cookie is not removed from the browser of the user. Therefore, as soon as the session has been abandoned, any new requests to the same application will use the same session ID but will have a new session state instance.
"If we don’t call Abandon method explicitly, the server destroys these objects when the session times out. Which means, for Session.Clear() and Session.RemoveAll(), just session data get removed, but session still alive, but Session.Abandon() Destroy the all object."
The main difference with Session.Clear() / Session.RemoveAll() and Session.Abandon()
- Clear removes items immediately from session collection, Abandon destroy the objects.
- Abandon raised Session.End()
- Clear keeps SessionState and resources associated with it where as abandon releases them and GC can collect them any time.
No comments:
Post a Comment