ASP.NET see if member is online

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 03:29:51

问题


I'm developing a ASP.NET site in umbraco, and I need to see if a member with a given ID is online. How can I do that?

So far, I've tried to get the member by so:

Member m = new Member(myID);

But how can I check, if the returned member is logged in or not?

EDIT: I followed the link, and extracted the following code from it:

var users = Membership.GetAllUsers();

foreach(MembershipUser user in users){
  Response.Write(user.IsOnline.ToString() +"<br/>");
  Response.Write(user.LastActivityDate.ToString() + "<br/>");
  Response.Write(user.LastLoginDate.ToString() + "<br/>");
}

However, the returned result shows that the property isOnline is true for every member, even though they're not online. I'm aware that it is because of the fact that the LastActivityDate updates automatically whenever I access the user, as stated here: Is it possible to access a profile without updating LastActivityDate?. Unfortunately, I don't get the solution to that question.

I've also tried to access the member by: MembershipUser m = Membership.GetUser('myID',false); But even though I put false as the second parameter, the LastActivityDate still updates. How can I work around this? I should note that I work with ASP.NET v. 4.0 in umbraco 4.7 at a localhost.

Thanks!

:EDIT END

Best regards, Brinck10


回答1:


You can use the MembershipUser.IsOnline Property that show true if the current date and time minus the UserIsOnlineTimeWindow property value is earlier than the lastActivityDate for the user.

There is an example on the MSDN page.

relative:
Proper 100% IsOnline implementation for asp.net membership
How to check in ASP.NET if the user is online?
asp.net custom membership provider: IsOnline property




回答2:


The solution to the problem:

(1) I made a costum field in the membertype called lastActivityDate.

(2) I placed a macro on the masterpage, update the member's lastActivityDate to the current time given that the member was online.

(3) On the validation page I checked if the lastActivityDate + CostumBuffer was bigger than DateTime.Now.

Thanks for your patience Aristos.



来源:https://stackoverflow.com/questions/11708070/asp-net-see-if-member-is-online

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!