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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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"];
Method 2
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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0