1

I have 3 active Sessions in my website Session["name"], Session["lastname"] and Session["username"], does Session.Abandon() will abandon all of them?

Katerina
  • 364
  • 6
  • 22

3 Answers3

4

Actually, you have one active session (not three). That session has those three key/value pairs associated with it.

Yes, Session.Abandon() will remove all of those variables in the process of abandoning the session, as soon as processing of the current page has finished.

Once the Abandon method is called, the current session is no longer valid and a new session can be started.

http://msdn.microsoft.com/en-us/library/system.web.sessionstate.httpsessionstate.abandon.aspx

When the Abandon method is called, the current Session object is queued for deletion but is not actually deleted until all of the script commands on the current page have been processed. This means that you can access variables stored in the Session object on the same page as the call to the Abandon method but not in any subsequent Web pages.

http://msdn.microsoft.com/en-us/library/ms524310(v=vs.90).aspx

UPDATE

If you want to "get rid of" the key/value pairs before the page finishes executing, you can clear them like this:

Session.Contents.RemoveAll()

http://msdn.microsoft.com/en-us/library/ms524866(v=vs.90)

Eric J.
  • 147,927
  • 63
  • 340
  • 553
0

Yes, the objects will be destroyed, but not immediately (from msdn)

When the Abandon method is called, the current Session object is queued for deletion but is not actually deleted until all of the script commands on the current page have been processed. This means that you can access variables stored in the Session object on the same page as the call to the Abandon method but not in any subsequent Web pages.

It is one session and 3 variables. If you need to remove them ASAP make them point to null and the data will immediately become subject for GC (which is not deterministic).

Session["name"] = null;
Session["lastname"] = null;
Session["username"] = null;
oleksii
  • 35,458
  • 16
  • 93
  • 163
  • is there anything that I can do to abandon them, like I can't access variables stored in the Session object on the same page as the call to the Abandon? – Katerina Jul 25 '12 at 15:55
0

Yes, it destroys all the objects stored in a Session object and releases their resources.

Pokemon
  • 63
  • 11