asp.net – MembershipUser.IsOnline即使在注销后也是如此

我正在使用Visual Studio 2010创建一个网站.我使用SQL Server 2008中的默认成员资格模式进行用户身份验证.现在我面临着以下问题.

当用户注销时,该用户的membership.IsOnline属性应设置为false.但是没有发生; member.IsOnline属性的用户仍然是真的.

我使用LoginStatus控件为用户提供一个注销链接.

我试图跟随User.IsOnline = true even after FormsAuthentication.SignOut().但结果没有.

AFAIK,FormsAuthentication.SignOut与会员制度没有直接关系.因此,您必须按照您在问题中提到的手动更新LastActivityDate.并使用Membership.UserIsOnlineTimeWindow而不是-2.

从MSDN

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

MembershipUser user = Membership.GetUser(false);

FormsAuthentication.SignOut();

user.LastActivityDate = DateTime.UtcNow.AddMinutes(-(Membership.UserIsOnlineTimeWindow + 1));
Membership.UpdateUser(user);
翻译自:https://stackoverflow.com/questions/10467880/membershipuser-isonline-is-true-even-after-logout

转载注明原文:asp.net – MembershipUser.IsOnline即使在注销后也是如此