I have set UserIsOnlineTimeWindow =”2″ in web.config then my logout() function has been modified as
public ActionResult LogOff()
{
MembershipUser usr = Membership.GetUser();
usr.LastActivityDate = DateTime.Now.AddMinutes(-2);
FormsAuthentication.SignOut();
return RedirectToAction("Index", "Home");
}
Still after returning to Home after Logout still the User.IsOnline = true
Only after idle time of 2 minutes User.IsOnline = false
How to make the user Offline at FormsAuthentication.SignOut(); Please help.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Not sure if signOut is also considered as an activity.
I suggest you set the LastActivityDate after the SignOut method. And don’t forget to update the user info.
like this:
MembershipUser usr = Membership.GetUser(false); FormsAuthentication.SignOut(); usr.LastActivityDate = DateTime.Now.AddMinutes(-2); Membership.UpdateUser(usr);
I just tested in my App, it works.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0