1

I would like to know the difference between

Session.clear();

Session.Abandon();

Session.RemoveAll();

Please explain the difference I'm struggling with my session sign out.

Thank you in anticipation

Sreedhar Danturthi
  • 7,119
  • 19
  • 68
  • 111
  • possible duplicate of [In ASP.NET, when should I use Session.Clear() rather than Session.Abandon()?](http://stackoverflow.com/questions/347377/in-asp-net-when-should-i-use-session-clear-rather-than-session-abandon) – balexandre Mar 16 '11 at 17:12
  • The answer is too technical and the practical aspect is not discussed meaning when should we use session.clear(), in what circumstances should we use session.abandon() and session.removeall(). Just giving the definition would not be considered an answer meant no offence to anyone. We should also consider if the user is a novice and how lucid is the answer. Thanks any way for pointing out the similarity. – Sreedhar Danturthi Mar 16 '11 at 17:17
  • 4
    This is a site for programmers. If you can not understand a technical answer, this may not be the place for you. Voting to close as a duplicate. – Andrew Barber Mar 16 '11 at 17:19
  • 1
    but the session.removeall was not explained and the practicality of usage was not discussed so thought posing a new question would clear out some of the equivocation – Sreedhar Danturthi Mar 16 '11 at 17:22
  • 2
    `RemoveAll` is the same as `Clear` as `RemoveAll` calls `Clear`. It exists merely to work with legacy code. For this, your question is exactly what the Duplicated asks/answer! – balexandre Mar 16 '11 at 17:33

2 Answers2

3

Session.Clear() removes all the content from the Object (values). The session with the same key is still alive.

Session.Abandon() destroys the session and the Session_OnEnd event is triggered. If you use this you will lose session and get a new session key. Consider using this with a "log out"

Session.RemoveAll() like Clear() this method deletes all items that have been added to the Session object's Contents collection.

Greg Zimmers
  • 1,390
  • 10
  • 6
0

Clear() and RemoveAll() perform the same thing: remove the session variables but keep the current session in memory. Whereas, Abandon() ends the current session.

Avi
  • 251
  • 1
  • 4
  • 14
  • what do u mean by removing the session variables and keeping the current session in memory ? Is removing the session variables not the same as removing the session ? Can you please explain in detail ? – Sreedhar Danturthi Mar 16 '11 at 17:19
  • 1
    It is not the same thing. Think of the session as a bucket and the session variables as items in the bucket. Clearing only removes the items in the bucket, not the bucket. Abandon removes the bucket. – Greg Zimmers Mar 16 '11 at 17:37
  • @Greg thats one of the best explanations i can think of ! Thank you so much – Sreedhar Danturthi Mar 16 '11 at 18:39