Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jun 14, 2011 12:29 PM by sirdneo
Jun 13, 2011 07:24 AM|LINK
we khnow The Abandon method is used to clear out session data and raise the Session_End event defined in the Global.asax and The clear method Clears all keys & values from the session-state item collection.but when do we should use
Session.Clear() instead of Session.Abandon() ? (please an example)
Jun 13, 2011 07:30 AM|LINK
Check this link.
Jun 13, 2011 07:31 AM|LINK
Session.Clear() clears out all the values stored in the session but it will keep the user session, so the session_end event will not be fired.Session.Abandon() kills user session and so the user will be assigend a new session id next time he/she visit the
Jun 13, 2011 07:56 AM|LINK
thanks a lot for your guidance but please tell me with an example when do we should use Session.Clear()
Jun 13, 2011 08:01 AM|LINK
You use Session.Clear() when you dont want to end the session but rather just clear all the keys in the session and reinitialize the session.
Session.Clear() will not cause the Session_End eventhandler in your Global.asax file to execute.
But on the other hand Session.Abandon() will remove the session altogether and will execute Session_End eventhandler.
Session.Clear() is like removing books from the bookshelf
Session.Abandon() is like throwing the bookshelf itself.
Jun 13, 2011 08:36 AM|LINK
So, if you use
Jun 13, 2011 10:30 AM|LINK
thanks a lot for your guidance but when session timeout is finished or we call Session.Clear() the user must relogin. what do you mean about "if you don't want him to relogin use Session.Clear()"
Jun 14, 2011 12:29 PM|LINK
Session.Clear removes all the variables stored in session and if user try to browse your site same sessionID will be used which was previously assigned to him.
Session.Abandon removes all the variables stored in session, fire session_end event and if user try to browse your site a new sessionID will be assigned to him.
what do you mean about "if you don't want him to relogin use Session.Clear()"
Either you call Session.Clear or session.Abandon, user will logout if you are using session to store his login status (almost in 99.99% sites session is user to login/logout users)