Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to count sessions in asp.net server application

Tags:

asp.net

There is a way to manage how many sessions an asp.net running aplication have? I want to exhibit it in a page, maybe with some other important information, if available. And, how can I do it?

like image 441
Alex Avatar asked Jun 02 '11 18:06

Alex


2 Answers

In global.asax, do the following:

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:

int LiveSessionsCount = (int) Application["LiveSessionsCount"];
like image 82
Akram Shahda Avatar answered Nov 09 '22 23:11

Akram Shahda


Perhaps in your global.asax file Session_Start and Session_End events, you can store session information to a userinfo array within your application state object. Then you can manage this array from App State throughout your application.

like image 36
Nick Rolando Avatar answered Nov 10 '22 01:11

Nick Rolando