views:

27

answers:

1

I am trying to create an admin screen that will give me details about all open sessions in an application/site. I would also like to know how many session objects are active for each of them

Session object gives me info about my current session. How do i find info about all open sessions. How many sessions are active, etc.

Thanks,

SK

+1  A: 

Assuming you want to do this in your ASP.Net code, and not by using a web server tool, you can increment a counter in an Application (or Cache) variable on Session_Start, and decrement it on Session_End in Global.asax.

If you want to know more than the count of active users, you can accumulate user information in a collection there -- a List<T> of User objects, perhaps.

Here's some code to get you started with this approach:

    protected void Session_Start(object sender, EventArgs e)
    {
        Application.Lock();
        Application["SessionCount"] = Convert.ToInt32(Application["SessionCount"]) + 1;
        Application.UnLock();
    }

    protected void Session_End(object sender, EventArgs e)
    {
        Application.Lock();
        Application["SessionCount"] = Convert.ToInt32(Application["SessionCount"]) - 1;
        Application.UnLock();
    }
DOK
This is more like telling me the total number of concurrent users on my site. Ok...that was the easy part. But I would also like to know how many session objects are active for each of them.
Sash
You might want to edit your question so that it indicates what information you are actually looking for. You aren't mentioning session objects there.
DOK