Want to Count the number of sessions that are active ?

Posted by .Netlearner under ASP.NET on 6/11/2012 | Points: 10 | Views : 1671 | Status : [Member] | Replies : 2
Hello All,

Am having a page in which i want to display the content when then sessions are zero and when the session is active and it contains he value i want to display the content regarding the session value.

Can i count the session? if yes how this is possible ? else what condition must be used ?




Responses

Posted by: Santhiram on: 6/11/2012 [Member] Starter | Points: 25

Up
0
Down
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"];

Thanks
Madhu

.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ajay.Kalol on: 6/11/2012 [Member] Starter | Points: 25

Up
0
Down
This is correct answer for counting session currently on in the Application.

Ajay
ajaypatelfromsanthal.blogspot.in

.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response