How to count number of active session for State Server Session Mode ?

How to count number of active session for State Server Session Mode ?

While dealing with ASP.NET Session, generaly we use Session_Start() method in Global.aspx for count the number of active session, as whenever a new session start, it invoked the Session_Start method. Generally most of the developer use an Application variable with in Session_Start method to count the total number of active session as shown in below.

01
02
03
04
05
06
07
08
09
10
void Session_Start(object sender, EventArgs e)
 
 {
  if (Application["OnlineCounter"] != null)
  {
    Application.Lock();
    Application["OnlineCounter"] = ((int)Application["OnlineCounter"]) + 1;
    Application.UnLock();
  }
}

But, sometime, when we don’t have this kind of implementation with in code and we want to get the count of active seesion, we can use this handy tip. State Server Session is not dependent on Worker Process, So, even if application pool got recycled, state server will remain maintain the session data. You can check the same active session count at any point of time. Without using any single line of code block we can count the number of active session for State Server Session using Performance Monitor Tool.  From Performance Tool > Add New Counter > Select State Server Session Total under “ASP.NET State Service”

image

After the selection, click on OK.

image

By default graphics mode will be “Line” chart. To get the number of count, just change it to Report, though you can check it on Line or Histogram mode as well.  Once you have set with “Report Mode” you will get the session count to 0 as there is no session

image

Now, for any new Session, State server will increase the count, this will be be update automatically in the “State Server Session Total” variable”

image

Abhijit Jana

Abhijit runs the Daily .NET Tips. He started this site with a vision to have a single knowledge base of .NET tips and tricks and share post that can quickly help any developers . He is a Former Microsoft ASP.NET MVP, CodeProject MVP, Mentor, Speaker, Author, Technology Evangelist and presently working as a .NET Consultant. He blogs at http://abhijitjana.net , you can follow him @AbhijitJana . He is the author of book Kinect for Windows SDK Programming Guide.

One Comment to “How to count number of active session for State Server Session Mode ?”

Comments are closed.