Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MembershipUser.IsOnline is true even after logout

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.

like image 563
Krishanu Dey Avatar asked May 06 '12 03:05

Krishanu Dey


1 Answers

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);
like image 115
Mehdi Golchin Avatar answered Sep 18 '22 18:09

Mehdi Golchin