开发者

ASP.NET MVC Membership GetNumberOfUsersOnline returning incorrect value

开发者 https://www.devze.com 2023-02-08 16:28 出处:网络
I have the following line in a Controller ViewData[\"UsersOnLineNow\"] = Membership.GetNumbe开发者_如何转开发rOfUsersOnline().ToString();

I have the following line in a Controller

ViewData["UsersOnLineNow"] = Membership.GetNumbe开发者_如何转开发rOfUsersOnline().ToString();

I am logged in as an Administrator but the above is returning a value of 0, verified by QickWatch. I was expecting a value of 1.

I also have the following in the Controller

ViewData["RegisteredUsers"] = Membership.GetAllUsers().Count.ToString();

This is returning the correct value of 2, myself included.

Anyone else had problems in this area?


MSDN:

GetNumberOfUsersOnline returns the number of users for the current ApplicationName where the last-activity date is greater than the current time less the UserIsOnlineTimeWindow. The last-activity date/time stamp is updated to the current date and time when user credentials are validated by way of the ValidateUser or UpdateUser method or when a call to a GetUser overload that takes no parameters or one that uses the userIsOnline parameter to specify that the date/time stamp should be updated.

Tip: You can try setting your UserIsOnlineTimeWindow to a higher value. Default value is 15 minutes, in the following example I've set it to 60.

<membership defaultProvider="AspNetSqlMembershipProvider"
  userIsOnlineTimeWindow="60">
  <providers>
    <add name="AspNetSqlMembershipProvider"
      type="System.Web.Security.SqlMembershipProvider"
      connectionStringName="ApplicationServices" 
         enablePasswordRetrieval="false" 
         enablePasswordReset="true" 
         requiresQuestionAndAnswer="false" 
         requiresUniqueEmail="false" 
         maxInvalidPasswordAttempts="5" 
         minRequiredPasswordLength="6" 
         minRequiredNonalphanumericCharacters="0" 
         passwordAttemptWindow="10" 
         applicationName="/" />
  </providers>
</membership>
0

精彩评论

暂无评论...
验证码 换一张
取 消