How to count sessions in an asp.net server application

Is there a way to control the number of sessions an asp.net application is running? I want to show it on the page, possibly with other important information, if any. And how can I do this?

+5
source share
2 answers

In global.asaxfollow these steps:

Handle the event Application.Startby adding the following:

Application["LiveSessionsCount"] = 0;

Handle the event Session.Startby adding the following:

Application["LiveSessionsCount"] = ((int) Application["LiveSessionsCount"]) + 1;

Handle the event Session.Endby adding the following:

Application["LiveSessionsCount"] = ((int) Application["LiveSessionsCount"]) - 1;

To get the number of sessions on your page, write the following:

int LiveSessionsCount = (int) Application["LiveSessionsCount"];
+11
source

, session_Start Session_End global.asax userinfo . .

+2

All Articles