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

5
  • possible duplicate of In ASP.NET, when should I use Session.Clear() rather than Session.Abandon()? Commented Mar 16, 2011 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. Commented Mar 16, 2011 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. Commented Mar 16, 2011 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 Commented Mar 16, 2011 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! Commented Mar 16, 2011 at 17:33

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

would you kind enough to say why do u need a new session key in case of logout ?
so if i use session.removeall() in logout won't the user be able to login next time ?
Because it will release the session state object and its items on the server so they can be garbage collected.
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.

3 Comments

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 ?
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 thats one of the best explanations i can think of ! Thank you so much

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.