views:

379

answers:

2

How can you find out the number of active users when you're using a StateServer? Also is it possible to query the StateServer and retrieve the contents in the Session State?

I know that this is all possible if you use SqlServer for a backing store, but I want them to be in memory.

A: 

Tracking the number of users would need to be done at the application level, not the session level.

You should be able to see what is currently in the session with the following:

StringBuilder builder = new StringBuilder();
foreach ( String key in Session.Contents ) {
    builder.AppendFormat("{0}: {1}<br />", key, Session[key]);
}
Response.Write(builder.ToString());
Hellfire
A: 

The number of active sessions in the State Server can be viewed with a Performance Counter on the server running the State Server easily. This does not directly equate to active users (due to session timeout time)

The counter for active sessions is: "Asp.net" - "State Server Sessions Active"

For reference, here are all State Server related perfmon counters, from http://msdn.microsoft.com/en-us/library/fxk122b4.aspx

State Server Sessions Abandoned The number of user sessions that have been explicitly abandoned. These are sessions that are ended by specific user actions, such as closing the browser or navigating to another site. This counter is available only on the computer where the state server service (aspnet_state) is running.

State Server Sessions Active The number of currently active user sessions. This counter is available only on the computer where the state server service (aspnet_state) is running.

State Server Sessions Timed Out The number of user sessions that have become inactive through user inaction. This counter is available only on the computer where the state server service (aspnet_state) is running.

State Server Sessions Total The number of sessions created during the lifetime of the process. This counter is the total value of State Server Sessions Active, State Server Sessions Abandoned, and State Server Sessions Timed Out. This counter is available only on the computer where the state server service (aspnet_state) is running.

Tormod Hystad