MembershipUser.IsOnline is true even after logout
Asked Answered
T

1

13

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.

Tearoom answered 6/5, 2012 at 3:34 Comment(0)
C
15

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);
Catacaustic answered 6/5, 2012 at 3:53 Comment(4)
Thank you for the additional information. This will help me on further approaches.Tearoom
This solution is working with the SqlMembershipProvider but not with the "Microsoft ASP.NET Universal Providers 1.1". When using the "Microsoft ASP.NET Universal Providers 1.1", calling UpdateUser will override the LastActivityDate property with DateTime.UtcNow.Holmun
@doitgood absolutely you're right, that was my bad and in my opinion it's not just about universal providers but the default SqlMembershipProvider as well as it's definitely required. Thanks for your remark :)Catacaustic
According to the Microsoft documentation, the LastActivityDate "should" be updatabable with the code you provided. This is probably a bug in the "universal providers". This link is from the MS documentation stating that the LastActivityDate is RW : msdn.microsoft.com/en-us/library/…Holmun

© 2022 - 2024 — McMap. All rights reserved.