Q:
I know that to destroy all sessions , i can use:
Session.Abandon()
According to my question.
but why there is n't any equivalent method to destroy only one session. and i am supposed to use
Session.Remove("varName")
instead of.
Q:
I know that to destroy all sessions , i can use:
Session.Abandon()
According to my question.
but why there is n't any equivalent method to destroy only one session. and i am supposed to use
Session.Remove("varName")
instead of.
First of all, you are talking about session variables, not sessions. Each user has one session and one Session object that you can store several variables in.
You use the Session.Abandon to abandon the session once the current request completes, which will remove the Session object.
You use the Session.Remove method to remove one variable from the Session object.
Session.Clear() will remove all items from the session-state collection while Session.Remove(<item name>) will remove only the one item from the collection and leave the remainder intact. Session.Abandon() will destroy the whole session and start a new session.
You are mistaken between Session and Session Variables. A User viewing your site is assigned only 1 session and in this 1 session object, you can store many session variables.
Session.Abandon will remove the current session of the connected user.
Session.Remove will remove specific session variables as mentioned by you.
Session.Clear will remove all the session variables of the session but will not remove the session.
Refer to the following links for the Session and its usage: