Last post Jun 14, 2011 01:29 PM by sirdneo
Jun 13, 2011 08:24 AM|aahn77|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 08:30 AM|Lateef045|LINK
Check this link.
Jun 13, 2011 08:31 AM|anas|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 08:56 AM|aahn77|LINK
thanks a lot for your guidance but please tell me with an example when do we should use Session.Clear()
Jun 13, 2011 09:01 AM|Lateef045|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 09:36 AM|Raigad|LINK
So, if you use
Jun 13, 2011 11:30 AM|aahn77|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 01:29 PM|sirdneo|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)