What is the difference between Session.Abandon()
and Session.Clear()
in ASP.Net?
The Abandon method destroys all the objects stored in a Session object and releases their resources. If you do not call the Abandon method explicitly, the server destroys these objects when the session times out.
We can clear the session storage by using the clear() method. Example: HTML.
The HttpSessionState. Abandon() method destroys all objects stored in a Session object and releases their resources. We call this method in ASP.Net with Session. Abandon().
RemoveAll is like a twin, Both will immediately remove all stored values from session, but the session object still in the memory.
Session.Abandon()
will destroy/kill the entire session.
Session.Clear()
removes/clears the session data (i.e. the keys and values from the current session) but the session will be alive.
Compare to Session.Abandon() method, Session.Clear() doesn't create the new session, it just make all variables in the session to NULL.
Session ID will remain same in both the cases, as long as the browser is not closed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With