Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / September 2007

Tip: Looking for answers? Try searching our database.

Counting number of users logged in

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike P - 07 Sep 2007 10:57 GMT
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?
Mark Rae [MVP] - 07 Sep 2007 11:40 GMT
> 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...?

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Mike P - 07 Sep 2007 11:50 GMT
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?
Juan T. Llibre - 07 Sep 2007 12:56 GMT
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/
======================================
> 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 ***
Mark Rae [MVP] - 07 Sep 2007 13:44 GMT
> 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...?

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Juan T. Llibre - 07 Sep 2007 14:54 GMT
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/
======================================

>> 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 [MVP] - 07 Sep 2007 15:38 GMT
> re:
> !> Really..? How does it know...?
[quoted text clipped - 6 lines]
> 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...?

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Juan T. Llibre - 07 Sep 2007 15:44 GMT
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/
======================================

>> re:
>> !> Really..? How does it know...?
[quoted text clipped - 7 lines]
>
> Yes, but how can it possibly know when a client browser has been closed...?
Mark Rae [MVP] - 07 Sep 2007 15:51 GMT
> re:
> !> Yes, but how can it possibly know when a client browser has been
[quoted text clipped - 6 lines]
> 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...

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.