GetNumberOfUsersOnline
I have the following problem while using the GetNumberOfUsersOnline method of the Membership class: The function returns the total number of users instead.
On page 172, this function is used to display the number of users online. I have changed this example to display only users working for a particular company. This information is stored into the Profile of each user. So after executing the GetAllUsers() function to populate allUsers, I pass this value into another function, called GetMSSUsersFromUserCollection:
privateMembershipUserCollection GetMSSUsersFromUserCollection(MembershipUserCollection everyone)
{
foreach (MembershipUser user in everyone)
{
ProfileCommon prof = Profile.GetProfile(user.UserName);
if (prof.CompanyCode == "MyCompany") allMSSUsers.Add(user);
}
return allMSSUsers;
}
This returns only the users belonging to the "MyCompany" company.
In retrieving each user's profile however also updates the user's LastActivityDate field. When the next statement is called to GetNumberOfUsersOnline, this returns all users belonging to the "MyCompany", since it returns those users whose LastAcitivityDate is within the current date and time minus the userIsOnlineTimeWindow period defined in web.config. This obviously gives me the wrong number.
How else could I implement this functionality?
Thanks
Chris
|