When using the default session functionality of ASP.NET 3.5, is it possible to remove a session by its session id?
Update: I would like to completely remove a specific session, not just a part of it and not just the current user's session.
When using the default session functionality of ASP.NET 3.5, is it possible to remove a session by its session id?
Update: I would like to completely remove a specific session, not just a part of it and not just the current user's session.
are you looking for?
Session.Remove("sessionName");//Delete an item from the session
Session.RemoveAll();//Remove all keys and values from the session-state collection
Session.Abandon();//Cancel the current Session
Session.Clear();//Remove all keys and values from the session-state collection
The Abandon method destroys all the objects stored in a Session object and releases their resources. If you do not call the Abandon method explicitly, the server destroys these objects when the session times out.
When the Abandon method is called, the current Session object is queued for deletion but is not actually deleted until all of the script commands on the current page have been processed. This means that you can access variables stored in the Session object on the same page as the call to the Abandon method but not in any subsequent Web pages.
I do not think it is possible to remove a specific session, as a user on the website only has access to his / her own session. This session can be removed via Session.Abandon() and friends as Muhammad Akhtar and adamantium pointed out.
Sessions time out, so inactive sessions are removed automatically after the session timeout, a value that can be set by you, e.g. in the web.config. Maybe you are looking for a solution to a problem that does not exist. See MSDN1 or MSDN2.