Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Session.Abandon() and Session.Clear() in ASP.Net?

What is the difference between Session.Abandon() and Session.Clear() in ASP.Net?

like image 968
Piyush Avatar asked Jun 11 '10 09:06

Piyush


People also ask

What is session abandon 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.

Which method is used to clear the session values?

We can clear the session storage by using the clear() method. Example: HTML.

How do you abandon a session?

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().

What removes all the session items but doesn't end the session?

RemoveAll is like a twin, Both will immediately remove all stored values from session, but the session object still in the memory.


1 Answers

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.

like image 174
Laxmi Avatar answered Sep 28 '22 03:09

Laxmi