2

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

Community
  • 1
  • 1

2 Answers2

3

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

Community
  • 1
  • 1
Aristos
  • 66,005
  • 16
  • 114
  • 150
  • @FrederikBrinckJensen see the example on MSDN page, you need to get all users that are online and find the one you looking for. (and is not 100% accurate) – Aristos Jul 29 '12 at 11:57
  • I'm sorry, but though I've read the MSDN page and tried their example, I still don't get it. See my EDIT. – Frederik Brinck Jensen Jul 29 '12 at 12:30
  • @FrederikBrinckJensen yes I know, there is some issues regarding this flag, thats why I have the other links on the answer, reads them out – Aristos Jul 29 '12 at 12:41
  • Well, I've tried now to use sessions but with no luck. I might elaborate a little on my question. The thing is, that whenever a user is online, he should be able to access some manuals online. That is done by requesting an external URL, which then makes a callback to my server to see if the given user is online. I cannot do so, because the sessions are stored locally, so how am I going to check, if the user is online? @Aristos, would you please elaborate? I read your links thoroughly, but couldn't come up with a solution. – Frederik Brinck Jensen Aug 10 '12 at 20:49
0

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.