C# – How to get a collection of Session State objects in ASP.NET

asp.netasp.net-mvccsession

How do I get the collection of all Session objects in ASP.NET? (Note that I am NOT looking for a collection of objects stored in the Session object but all of the session objects themselves.)

This is for an admin page that will list all active sessions and if the user is logged in will also list the user name etc.

Language: C#
Framework: ASP.NET MVC 1.0 (3.5 SP1)

EDIT: A couple of good answers so far with a solution that I had thought of but not mentioned in my original question which is to add and remove the session objects in session_onStart and session_onEnd. The reason that I haven't done this yet is that I find it hard to believe that the collection of Session objects is not exposed to us. I am guessing that ASP.NET stores this collection of Session objections in a collection of some type so I'm trying to find out how to get hold of that collection. I am happy to write the extra code to manage it myself but am not a fan of creating extra overhead and code to maintain if this functionality already exists.

Best Answer

you can use global asax and following methods.

sub session_onStart() 

    application.lock() 
    // your logic
    application.unlock() 

end sub 

sub session_onEnd() 

    application.lock() 
// your logic
    application.unlock() 

end sub