| Author: Shivshanker Cheral 04 Jul 2008 | Member Level: Diamond | Rating: Points: 6 |
refer
Global.asax with the following for tracking the user sessions and displaying the count of logged in users, but this doesn't work properly for users who just close their browsers or logout of the application. In addition my update panel is never updating the count in realtime.
void Application_Start(object sender, EventArgs e) { // Start tracking the number of active sessions when the application starts. Application.Add("userLoginCount", 0);}void Session_Start(object sender, EventArgs e) { // Increase the count of active sessions as they come on. int userLoginCount = Convert.ToInt32(Application.Get("userLoginCount").ToString()); userLoginCount++; Application.Set("userLoginCount", userLoginCount);}void Session_End(object sender, EventArgs e) { // Decrease the number of active sessions as they end. int userLoginCount = Convert.ToInt32(Application.Get("userLoginCount").ToString()); userLoginCount--; Application.Set("userLoginCount", userLoginCount); }On my MasterPage I a label that contains the count. I've created a property, so that I can access the label as opposed to using FindControl.The code below is on my Default.aspx page. // Get the number of active sessions and display it. Master.GetSessionCount = Application.Get("userLoginCount").ToString();
http://forums.asp.net/t/1155945.aspx
|
| Author: Siddesh Kapadi 04 Jul 2008 | Member Level: Silver | Rating: Points: 4 |
Set a session variable when a user visits the page and unset the variable when the user goes to some other page and increase the count when the user session is set. This will help you eliminate the user page refresh scenario.
|