views:

76

answers:

2

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.

+2  A: 

You could use the global.asax file and add some custom code to the Session_OnStart event, you can get the user information and update it in a database which can feed your admin page.

RandomNoob
+1 That is one solution I was thinking of. I was going to create a list of Session objects and store it in the Application object but I find it hard to believe that list is not already available to us.
Guy
+3  A: 

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
Saar
+1 Yes, this is my fallback solution but as I mentioned in the other answer I find it hard to believe that this collection is not available to us already.
Guy