Please give me your valuable answers
When the user clicks on Signout or logout we need to clear session. By default session expires after 20 min of ideal state.
Better to use login controls for this and handle "LoggedOut" and "LoggingOut" events of LoginStatus status control.
Session.Clear() clears the all session variables value whereas Session.Abandon() vanishes(kills) the session.
When you want to clear your session data that time you can call these methods.
Especially while logout/signout you can call these methods if you you are storing user/login information in session.
Some differences are,
1.Session.Abandon() will end current session by firing Session_End and in the next
request, Session_Start will be fire.
2.Session.Clear( ) just clears the session data without killing it. With session.clear
variable is not removed from memory it just like giving value null to this session.
Session ID will remain same in both cases, as long as the browser is not closed.
It's best coding practice to clear your session after logout.
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.
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)