MembershipUser.IsOnline is true even after logout

本秂侑毒 提交于 2019-12-21 03:41:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!