469,963 Members | 2,006 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,963 developers. It's quick & easy.

Counting number of users logged in

What would be the best way of counting the number of users who are
currently logged on to a website? I am making the users login against a
database of valid users. Would the best way be to add a bool field to
the table and set each user to 1 if they are logged in, and 0 if they
are not logged in?

*** Sent via Developersdex http://www.developersdex.com ***
Sep 7 '07 #1
8 3560
"Mike P" <mi*******@gmail.comwrote in message
news:eX**************@TK2MSFTNGP02.phx.gbl...
What would be the best way of counting the number of users who are
currently logged on to a website? I am making the users login against a
database of valid users. Would the best way be to add a bool field to
the table and set each user to 1 if they are logged in, and 0 if they
are not logged in?
Depends if you need to know only the number of currently logged-in users, or
who they actually are...

However, what happens if e.g. 100 users log in and then all close their
browser without logging off...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 7 '07 #2
That is the thing I don't know how to do....I can capture which users
have clicked on a Logoff link, but how do I capture which users have
just closed the browser window, or those who have left the browser open
and whose session has timed out?

*** Sent via Developersdex http://www.developersdex.com ***
Sep 7 '07 #3
re:
!how do I capture which users have just closed the browser window

You can't, unless you're using the Membership class for logins.

re:
!those who have left the browser open

You can't.

re:
!whose session has timed out?

You *can*, by capturing the Session_OnEnd events, but only if you're using InProc
session state management and relying on counting the number of sessions active.

If you're using SQL Server session state management or State Server,
the Session_OnEnd event ( also referred to as Session_End ) will never fire.

So, at most, you can keep track of how many sessions are active,
but not how many users are actually connected, if you rely on counting active sessions.

Btw, you didn't say whether you're using the Membership class for logins, but if you are,
you can trap the number of users logged in with Membership.GetNumberOfUsersOnline().

Simple, huh ? ...but it only works if you're using logins and Membership.


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"Mike P" <mi*******@gmail.comwrote in message news:%2****************@TK2MSFTNGP02.phx.gbl...
That is the thing I don't know how to do....I can capture which users
have clicked on a Logoff link, but how do I capture which users have
just closed the browser window, or those who have left the browser open
and whose session has timed out?

*** Sent via Developersdex http://www.developersdex.com ***

Sep 7 '07 #4
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
re:
!how do I capture which users have just closed the browser window

You can't, unless you're using the Membership class for logins.
Really..? How does it know...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 7 '07 #5
re:
!Really..? How does it know...?

It keeps track of them with :

public static int GetNumberOfUsersOnline();
Declaring Type: System.Web.Security.Membership

Use Lutz Roeder's Reflector to look up System.Web.Security.Membership class's source.


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message news:%2***************@TK2MSFTNGP02.phx.gbl...
"Juan T. Llibre" <no***********@nowhere.comwrote in message news:%2****************@TK2MSFTNGP06.phx.gbl...
>re:
!how do I capture which users have just closed the browser window

You can't, unless you're using the Membership class for logins.

Really..? How does it know...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net


Sep 7 '07 #6
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:eX**************@TK2MSFTNGP03.phx.gbl...
re:
!Really..? How does it know...?

It keeps track of them with :

public static int GetNumberOfUsersOnline();
Declaring Type: System.Web.Security.Membership

Use Lutz Roeder's Reflector to look up System.Web.Security.Membership
class's source.
Yes, but how can it possibly know when a client browser has been closed...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 7 '07 #7
re:
!Yes, but how can it possibly know when a client browser has been closed...?

It can't, but if a user has closed the browser, the user will still be logged in,
at least until his session times out.

It keeps track of "logged in" users, not active users, like so many counters.

Otoh, it's real easy to implement, even if it doesn't provide an accurate, real, count... ;-)


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message news:%2****************@TK2MSFTNGP05.phx.gbl...
"Juan T. Llibre" <no***********@nowhere.comwrote in message news:eX**************@TK2MSFTNGP03.phx.gbl...
>re:
!Really..? How does it know...?

It keeps track of them with :

public static int GetNumberOfUsersOnline();
Declaring Type: System.Web.Security.Membership

Use Lutz Roeder's Reflector to look up System.Web.Security.Membership class's source.

Yes, but how can it possibly know when a client browser has been closed...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 7 '07 #8
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
re:
!Yes, but how can it possibly know when a client browser has been
closed...?

It can't, but if a user has closed the browser, the user will still be
logged in,
at least until his session times out.

It keeps track of "logged in" users, not active users, like so many
counters.
Ah right - that's what I thought - you had me worried for a second there...
:-)
Otoh, it's real easy to implement, even if it doesn't provide an accurate,
real, count... ;-)
Yes indeed - I have my own implementation of that...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 7 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by mr_burns | last post: by
3 posts views Thread by A Seel | last post: by
3 posts views Thread by RogueIT | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.