问题
I'm currently creating a website using Visual Studio 2010. I'm using the default membership schema in SQL Server 2008 for user authentication. Now I'm facing the following problem.
When a user logs out, the membership.IsOnline property of that user should be set to false. However that it is not happening; membership.IsOnline property of that user is still true.
I'm using the LoginStatus control to provide a logout link to the user.
I have tried to follow User.IsOnline = true even after FormsAuthentication.SignOut(). But results nothing.
回答1:
AFAIK, FormsAuthentication.SignOut doesn't have a direct relationship to Membership system. Thus, you have to update the LastActivityDate
manually as you mentioned in your question. And use Membership.UserIsOnlineTimeWindow instead of -2.
From 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