picnic4u picnic4u - 2 months ago 7
ASP.NET (C#) Question

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?

Answer

Session.Abandon() will end the current session. Session_End will be fired and the next request will fire the Session_Start event.

Session.Clear will just clear the session data and the the session will remain alive.

Session ID will remain the same in both cases, as long as the browser is not closed.

In a nutshell:

Session.Abandon(); cancels the current Session.

Session.Clear(); clears all values from Session state.