UserConcurrency
-
How can I count the number of online users on my site? I have implemented my application as follows. Whenever a user logs in, I increment the count field in my database by 1 in Session_Begin and on Session_End I decrement it by 1.Though the code works fine in normal circumstances, I noticed a few anamolies: 1. If the user refreshes his browser, the Session_Begin is called again and the counter is incremented again. To overcome this, I used cookies. The first time the user logs in, I create the cookie. When the user refreshes his browser, it checks if the cookie exists, if it doesnt it treats it as a new request and updates the counter accordingly. 2. The problem arises on log out. Whenever the user refreshes his browser, Session_End is called that many times, and my counter is decremented more than once. How can I get Session_End to run only once for each instance of the browser? 3. I'm using Forms Authentication and on Session_End I want to call FormsAuthentication.SignOut since the user can still access the pages after the session ends,causing a new session to be started. But this function does not work in Session_End.
-
How can I count the number of online users on my site? I have implemented my application as follows. Whenever a user logs in, I increment the count field in my database by 1 in Session_Begin and on Session_End I decrement it by 1.Though the code works fine in normal circumstances, I noticed a few anamolies: 1. If the user refreshes his browser, the Session_Begin is called again and the counter is incremented again. To overcome this, I used cookies. The first time the user logs in, I create the cookie. When the user refreshes his browser, it checks if the cookie exists, if it doesnt it treats it as a new request and updates the counter accordingly. 2. The problem arises on log out. Whenever the user refreshes his browser, Session_End is called that many times, and my counter is decremented more than once. How can I get Session_End to run only once for each instance of the browser? 3. I'm using Forms Authentication and on Session_End I want to call FormsAuthentication.SignOut since the user can still access the pages after the session ends,causing a new session to be started. But this function does not work in Session_End.
How about creating a dynamic array (ArrayList for instance) of the Session IDs? On Session_Begin, add the ID to the array if it doesn't currently exist, on Session_End, remove the Session_ID. TrimToSize each time and use the Count to get the number of active sessions. I seem to remember a similar solution in traditional ASP using the Dictionary object... Just because I don't care, doesn't mean I don't understand. - Homer J. Simpson
-
How can I count the number of online users on my site? I have implemented my application as follows. Whenever a user logs in, I increment the count field in my database by 1 in Session_Begin and on Session_End I decrement it by 1.Though the code works fine in normal circumstances, I noticed a few anamolies: 1. If the user refreshes his browser, the Session_Begin is called again and the counter is incremented again. To overcome this, I used cookies. The first time the user logs in, I create the cookie. When the user refreshes his browser, it checks if the cookie exists, if it doesnt it treats it as a new request and updates the counter accordingly. 2. The problem arises on log out. Whenever the user refreshes his browser, Session_End is called that many times, and my counter is decremented more than once. How can I get Session_End to run only once for each instance of the browser? 3. I'm using Forms Authentication and on Session_End I want to call FormsAuthentication.SignOut since the user can still access the pages after the session ends,causing a new session to be started. But this function does not work in Session_End.
Use application variable instead of session variable. Now U become free from session. Now check if page is refreshed by session variable. If the browser is refreshed and new session start then chk it on higher version browser, or better ie 5.5 and netscape 7.0, and I think this problem will not exist. If still exist then you have nothing to do. But I am sure the problem will not exist. Himadrish Laha