Last post Jan 21, 2011 08:57 PM by JonathanWood
Jan 21, 2011 03:10 PM|Acoustic1978|LINK
I'm using the following line of code to display the number of users currently logged on:
lblNoOfUsers.Text = Membership.GetNumberOfUsersOnline().ToString()
I'm still debugging my application so it's on the local server. As I debug and stop then debug again, eventually lblNoOfUsers.text turns to "0" instead of "1", even as I'm navigating my application. It only turns to "1" again if I log out and sign back
It's almost as though Membership.GetNumberOfUsersOnline my login are referencing two different session states. How is this possible? Does asp.net create a new session state cookie each time I start debugging?
Jan 21, 2011 03:53 PM|DarrellNorton|LINK
GetNumberOfUsersOnline tries to "guess" how many users are online based on the last login date and the UserIsOnlineTimeWindow.
The UserIsOnlineTimeWindow property value is checked during the call to GetNumberOfUsersOnline.
If the LastActivityDate for a user is greater than the current date and time minus
theUserIsOnlineTimeWindow value in minutes, then the user is considered online. You can determine whether a membership user is considered online with the IsOnline property
of the MembershipUser class.
The LastActivityDate for a user is updated when a user's credentials are successfully
validated by the ValidateUser method. You can also update the LastActivityDate for
a membership user when you call one of the GetUser overloads. If you call a GetUser overload
that takes a userIsOnline parameter, specify a value of true to update the LastActivityDate for
Jan 21, 2011 08:57 PM|JonathanWood|LINK
In addition to the other answer provided, I would just point out that there's no way possible to tell exactly how many people are on line.
I mean, you have a web server that serves a page to the client. You have no knowledge about if the user is viewing the content or turned off their computer.
GetNumberOfUsersOnline() uses a reasonable algorithm to guess at the current number of users. It is not, and cannot, be exact.