Last post Jun 14, 2011 08:29 AM by sirdneo
Jun 13, 2011 03: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 03:30 AM|Lateef045|LINK
Check this link.
Jun 13, 2011 03: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 03: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 04: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 04:36 AM|Raigad|LINK
Session.Abandon() destroys the session and the
Session_OnEnd event is triggered.
Session.Clear() just removes all values (content) from the Object. The session with the same key is still alive.
So, if you use Session.Abandon(), you lose that specific session and the user will get a new session key. You could use it for example when the user logs out.
Use Session.Clear(), if you want that the user remaining in the same session (if you don't want him to relogin for example) and reset all his session specific data.
Jun 13, 2011 06: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 08:29 AM|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)