locked
Session state question RRS feed

  • Question

  • User-1398449107 posted

    Hello forum,

    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 in. 

    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?

    Thank you

     

    Friday, January 21, 2011 3:10 PM

Answers

  • User-837620913 posted

    GetNumberOfUsersOnline tries to "guess" how many users are online based on the last login date and the UserIsOnlineTimeWindow.  

    From the documentation:

    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 the user.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, January 21, 2011 3:53 PM

All replies

  • User-837620913 posted

    GetNumberOfUsersOnline tries to "guess" how many users are online based on the last login date and the UserIsOnlineTimeWindow.  

    From the documentation:

    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 the user.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, January 21, 2011 3:53 PM
  • User-672208662 posted

    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.

    Friday, January 21, 2011 8:57 PM