Hi,
You can use Windows Performance counters for this (perfmon)
ASP.NET Applications > Sessions Active counter.
You can access these performance counters using the System.Diagnostics namespace.
In below code instead of MYSERVERHOSTNAME.domain pass your Serverhostname(i.e. MachineName)
C#
PerformanceCounter pc = new PerformanceCounter("ASP.NET Applications","Sessions Active", "__Total__", "MYSERVERHOSTNAME.domain");
while (true)
{
Console.WriteLine(pc.NextValue());
System.Threading.Thread.Sleep(1000);
}
Refer below link for more info
https://msdn.microsoft.com/en-us/library/fxk122b4.aspx
if the counter seems too high: http://support.microsoft.com/kb/969722
Also you can use Application State.(In Global.asax)
Handle the Application.Start
event adding the following:
Application["LiveSessionsCount"] = 0;
Handle the Session.Start
event adding the following:
Application["LiveSessionsCount"] = ((int) Application["LiveSessionsCount"]) + 1;
Handle the Session.End
event adding the following:
Application["LiveSessionsCount"] = ((int) Application["LiveSessionsCount"]) - 1;
To retrieve sessions count inside your page write the following:
nt LiveSessionsCount = (int) Application["LiveSessionsCount"];
I hope this will help you out.