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”
After the selection, click on OK.
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
Now, for any new Session, State server will increase the count, this will be be update automatically in the “State Server Session Total”
variable”
Pingback: Tips from Daily .NET Tips – Week 1 « Abhijit's World of .NET