views:

118

answers:

3

Is there any way to access the collection of current sessions in ASP.NET globally from the application?

Thanks.

+4  A: 

No, sessions are sandboxed, they are totally separate from each other. What you could do is managing a psueudo-session collection in the shared Application object and implement the Session_Start method to populate that collection.

driAn
A: 

I don't think so, but you can manage your own list in the global.a s a x

void Session_Start(object sender, EventArgs e) 
{
    //add current session to your own application shared collection
}

void Session_End(object sender, EventArgs e) 
{
    //remove session
}
pablito
Can you inspect the contents of the session though?
John Nolan
Session end event wouldn't occur if session is out of process, even in process, it isn't guaranteed that it's trigged: see note on http://msdn.microsoft.com/en-us/library/system.web.sessionstate.sessionstatemodule.end.aspx
smoothdeveloper
+1  A: 

If you store session state in SQL Server, you would have access to all the sessions via SQL Server.

There is also Application State - which can be used to access information across the application, but this has many caveats.

mson