Ok after a few hours research and testing here are my results:
The MembershipUser.IsOnline just checks if the LastActivityDate is greater than current time - OnlyTimeWindow.
The LastActivityDate is set when using CreateUser, UpdateUser and ValidateUser. Also it can be set by using GetUser(object,bool) where the bool value indicates if the date should be updated.
After I looked at the umbraco code i saw no point where the boolvalue is actually used, so the LastActivityDate never gets updated.
Also I tried so set the value manually on login/logout but after 30 minutes the users still was "online".
So as a result i think the IsOnline property just always returns true.
Maybe that should be added to the issue tracker.
If someone else has a working method I would be glad to here it.
List all currently logged in members
Hi
What approach would I need to list all currently logged in members?
I know there is a method that returns the current count
public override int GetNumberOfUsersOnline()
{
return umbraco.cms.businesslogic.member.Member.CachedMembers().Count;
}
However I wish to display a list of currently logged in member details
Thanks
I think you can do that by using the Membership Api.
Would be something like that i think:
With the ProviderUserKey you can than create the Umbraco Member with: var member = new Member(id);
Hope that is want you've been looking for.
OK thanks for your reply; I tried the following and it appears to list all of my previous logins and not just my current session.
List<MembershipUser> onlineUsers = new List<MembershipUser>();
foreach (MembershipUser ServiceAdvisorUser in Membership.GetAllUsers())
{
if (ServiceAdvisorUser.IsOnline)
{
onlineUsers.Add(ServiceAdvisorUser);
}
}
@*loop through and create umbraco members*@
List<Member> UmbracoLoggedInUsers = new List<Member>();
foreach(MembershipUser loggedInUser in onlineUsers)
{
Member member = new Member((int)loggedInUser.ProviderUserKey); // Umbraco Member class
UmbracoLoggedInUsers.Add(member);
}
In addition I did the same approach using
@foreach(Member loggedInMemberToDisplay in umbraco.cms.businesslogic.member.Member.CachedMembers())
However this is returning zero
I will try it again. But it seems that it should in general work.
One thing i discovered is that Membershit.GetAllUsers() also returns the users and not only the members.
So maybe using Member.GetAllAsList().Where(x => x.MemberType == yourmembertype); would be the better choice.
Ok after a few hours research and testing here are my results:
The MembershipUser.IsOnline just checks if the LastActivityDate is greater than current time - OnlyTimeWindow.
The LastActivityDate is set when using CreateUser, UpdateUser and ValidateUser. Also it can be set by using GetUser(object,bool) where the bool value indicates if the date should be updated.
After I looked at the umbraco code i saw no point where the boolvalue is actually used, so the LastActivityDate never gets updated.
Also I tried so set the value manually on login/logout but after 30 minutes the users still was "online".
So as a result i think the IsOnline property just always returns true.
Maybe that should be added to the issue tracker.
If someone else has a working method I would be glad to here it.
Thanks for your post David - I will keep digging and post if I come up with a solution.
is working on a reply...