编程语言
首页 > 编程语言> > c#-会员User.IsOnline定义

c#-会员User.IsOnline定义

作者:互联网

我有一个关于成员资格的问题,更确切地说是关于IsOnline属性的问题.我已经阅读了一些资源,但是我仍然不明白它的计算方式,工作原理以及工作原理.

所以根据msdn:

A user is considered online if the current date and time minus the
UserIsOnlineTimeWindow property value is earlier than the
LastActivityDate for the user.

可以在web.config中配置UserIsOnlineTimeWindow,但是默认设置是什么?

上次活动日期我不太清楚什么是上次活动日期?

如果用户没有在网站上做任何事情,但仍在该网站上,但会显示为离线,该怎么办?有没有办法让用户保持在线状态?

用户必须做的是,上次活动日期已更新?

如果有人能提供实数示例,我将不胜感激.谢谢

解决方法:

UserIsOnlineTimeWindow can be configured in the web.config, but what is the default?

我不知道默认值是什么,但是我想像一下,如果您打算使用IsOnline属性的默认行为,那么您至少希望将UserIsOnlineTimeWindow设置为特定值.

Last Activity Date i don’t really understand what is last activity date?

每当您使用CreateUser或ValidateUser方法时,LastActivityDate属性都会更新为当前的Datetime.您还可以自定义成员资格的其他方法以更新LastActivityDate,即GetUser().

And what if user haven’t done anything on the website but he is still present there, but he will be shown offline? Is there a way to keep user to be shown online?

这是UserIsOnlineTimeWindow起作用的地方:

public bool IsOnline {
    get 
    {
        return ((Datetime.Now - UserIsOnlineTimeWindow) < LastActivityDate)
        //this is the behavior that the MembershipProvider uses by default
        //as you already mentioned in your question
    }
}

根据此信息,您有两种选择:

>用您自己的实现覆盖IsOnline属性
>在其他Membership方法中更新LastActivityDate属性

What user has to do, that the last activity date was updated?

默认情况下,只能通过使用CreateUser,UpdateUser和ValidateUser进行更新,但是正如我之前所说,您可以自定义MembershipProvider以在需要时更新该属性.

标签:asp-net-membership,c
来源: https://codeday.me/bug/20191122/2058411.html