简体   繁体   English

Asp.net成员身份登录用户列表

[英]Asp.net Membership Logged in Users list

I used following in my application to find the list of logged in user. 我在应用程序中使用以下命令来查找已登录用户的列表。 It gives the list of logged in user but when i close the browser and clear the browser history, it shows the user isonline status true. 它提供了已登录用户的列表,但是当我关闭浏览器并清除浏览器历史记录时,它显示用户isonline状态为true。 Please can any one tell me where i am wrong? 请任何人告诉我我错了吗?

When User signIn am validating user and redirect to url, 当用户登录验证用户并重定向到网址时,

if (user != null)
{
     if (Membership.ValidateUser(user.UserName, txtUserPassword.Text))
     {
        FormsAuthentication.SetAuthCookie(txtUserName.Text, false);
     }
}

List of logged in user code 登录的用户代码列表

 MembershipUserCollection allUsers = Membership.GetAllUsers();

 MembershipUserCollection filteredUsers = new MembershipUserCollection();

 bool isOnline = true;
 foreach (MembershipUser user in allUsers)
 {
    // if user is currently online, add to gridview list
   if (user.IsOnline == isOnline)
   {
      filteredUsers.Add(user);
   }
 }

Not sure why you had a negative down vote, this was a valid question. 不确定为什么要投反对票,这是一个有效的问题。 You also may never see this answer but others may have the same problem. 您可能也永远也看不到这个答案,但是其他人可能也有同样的问题。

MembershipUser.IsOnline is not a very accurate check of whether or not a user is online. MembershipUser.IsOnline不是对用户是否在线的非常准确的检查。 From the MSDN , a user is determined to be online: MSDN ,确定用户在线:

if the current date and time minus the UserIsOnlineTimeWindow property value is earlier than the LastActivityDate for the user. 如果当前日期和时间减去UserIsOnlineTimeWindow属性值早于该用户的LastActivityDate。

This means the user could log in and then log out 10 seconds later and still be considered online. 这意味着用户可以登录,然后在10秒后注销,仍然被视为在线用户。

So in your case you were logging in, checking the count, logging out, closing the browser, clearing cache, etc., but the user's LastActivityDate still fell within the assumed window described above. 因此,在您的情况下,您正在登录,检查计数,注销,关闭浏览器,清除缓存等,但是用户的LastActivityDate仍然落在上述假定的窗口内。 What you can do is: 您可以做的是:

  • shorten the time window (which can produce some unwanted side effects) 缩短时间窗口(这可能会产生一些不必要的副作用)
  • when logging the individual out, update their LastActivityDate to a time that would make the above check invalid (eg, the current time UserIsOnlineTimeWindow ) 注销个人时,将其LastActivityDate更新为使上述检查无效的时间(例如,当前时间UserIsOnlineTimeWindow
  • update the LastActivityDate manually at certain key points (eg, if your site is bookstore, maybe updating the LastActivityDate when they add an item to the cart) 在某些关键点手动更新LastActivityDate (例如,如果您的网站是书店,则可能在他们将商品添加到购物LastActivityDate更新LastActivityDate

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM