Is it possible to remove a session by its ID?
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 开发者_如何学Golike to completely remove a specific session, not just a part of it and not just the current user's session.
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.
Session.Abandon
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.
精彩评论