What's the deal with Membership.GetNumberOfUsersOnline?

N

Nick

Hi there,

Membership.GetNumberOfUsersOnline() works great the first time, then
jumps up to the number of users registered in the system.

I have tried enumerating through each user individually and checking
IsOnline which done likewise, first result was 4, then 22 every time after
that and it's only be debugging locally using VS.

Either I'm doing something seriously wrong or this function is a
complete joke. I'm opting for the latter personally....

Any input on this would be greatly appreciated.

Nick.
 
S

Steven Cheng [MSFT]

Hi Nick,

From your description, you're encountering some problem when using
Membership.GetNumberOfUsersOnline API, correct?

According to your scenario, the number changed when you call it second
time. Based on my research, the GetNumberOfUsersOnline will be affected
when some of the following methods are called(from the MSDN document)

==================
The last-activity date/time stamp is updated to the current date and time
when user credentials are validated by way of the ValidateUser or
UpdateUser method or when a call to a GetUser overload that takes no
parameters or one that uses the userIsOnline parameter to specify that the
date/time stamp should be updated.
============

#Membership..::.GetNumberOfUsersOnline Method
http://msdn.microsoft.com/en-us/library/system.web.security.membership.getnu
mberofusersonline.aspx

Therefore, I wonder whehter any of the methods are called so that all the
users become activated before you call the GetNumberOfUsersOnline method
second time. You can also directly validate the database table's
"lastactiviated" field to verify the behavior.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
 
S

Steven Cheng [MSFT]

Hi Nick,

Any further quesiton on this issue?

Sincerely,

Steven Cheng
Microsoft MSDN Online Support Lead

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: (e-mail address removed) (Steven Cheng [MSFT])
Organization: Microsoft
Date: Thu, 31 Jul 2008 02:24:17 GMT
Subject: RE: What's the deal with Membership.GetNumberOfUsersOnline?
 
N

Nick

Hi Steven,

Sorry for the delayed reply, I've got several threads running at the
same time trying to do too much at once LOL!

The users are only being enumerated in one point and that's the
additional function i've made to count the number of users currently online,

---

int pIntCurCount = 0;
MembershipUserCollection pMUCUsers = Membership.GetAllUsers();
foreach (MembershipUser pMUrUser in pMUCUsers)
{
pIntCurCount += (pMUrUser.IsOnline ? 1 : 0);
}
lblUsersOnline.Text = String.Format("Users Online : {0} - ",
pIntCurCount.ToString());

---

This consistently produces the correct number the first time it is run,
then returns the total number of users the second time round. So it seems
that GetAllUsers must be modifying the flag as you suggest, but then that
just raises the question of how this could possibly be achieved other than
enumerating the database manually which imo, is nasty and shouldn't need to
be done.

So surely GetNumberOfUsersOnline is buggy? It doesn't produce a
consistently correct value, so must be surely?

More to the point, why is the users last logged in date changed at all
during any of these calls? Why not leave it down to the user to update the
value via a manual invocation of an update method. If this is the correct
behaviour, it is pretty poor unfortunately.

Nick.
 
S

Steven Cheng [MSFT]

Hi Nick,

Per the document, the method call on "MembershipUser.IsOnline" may update
its online status. Therefore, I suggest you try calling
"Membership.GetNumberOfuserOnline" several times without accessing each
user's IsOnline property(remove the foreach loop). I think it will make the
"Membership.GetNumberOfuserOnline" call return the consistent result.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Subject: Re: What's the deal with Membership.GetNumberOfUsersOnline?
Date: Wed, 6 Aug 2008 13:40:40 +0100
 
N

Nick

Hi Steven

No it won't you, have completely misunderstood. I wrote that method as
an alternative to GetNumberOfUsersOnline, neither of which produce
consistent results.

In fact, that code sample doesn't even have a call to
GetNumberOfUsersOnline in it.

Nick.
 
S

Steven Cheng [MSFT]

Thanks for your reply Nick,

I have performed some local tests(using the default SQLExpress membership
provider). Here is a test page I used two buttons to simulate two methods
to check Users online:


==============================
public partial class status : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
foreach (MembershipUser user in Membership.GetAllUsers())
{
Response.Write("<br/>" + user.UserName + ": " + user.IsOnline);
}
}
protected void Button2_Click(object sender, EventArgs e)
{
Label1.Text = "Users Online: " +
Membership.GetNumberOfUsersOnline().ToString();
}
}
======================

It seems the result will keep the same when I press the button multiple
times. BTW, if you have created a new user via "createUserWizard" , the
user may be set to online status. You may need to logout first(also it may
take some time to make it take effect due to the delay used for the
membership to calculate the expire).

for your scenario, do you mean if you click such button multiple times, it
will return different results?

Sincerely,

Steven Cheng
Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
<[email protected]>
Subject: Re: What's the deal with Membership.GetNumberOfUsersOnline?
Date: Fri, 8 Aug 2008 13:43:10 +0100
 
N

Nick

Hi Steven,

I have found the problem, further down in the code there is an offending
GetUser call, this has been fixed and now the problem is resolved. Thanks a
million for your time, it's been most appreciated.

Nick.
 
S

Steven Cheng [MSFT]

You're welcome Nick.

Glad that you've figured it out!

Sincerely,

Steven Cheng
Microsoft MSDN Online Support Lead

--------------------
From: "Nick" <[email protected]>
Subject: Re: What's the deal with Membership.GetNumberOfUsersOnline?
Date: Thu, 21 Aug 2008 10:54:48 +0100
Hi Steven,

I have found the problem, further down in the code there is an offending
GetUser call, this has been fixed and now the problem is resolved. Thanks
a
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,088
Latest member
JeremyMedl

Latest Threads

Top