473,748 Members | 6,418 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3746
"Mike P" <mi*******@gmai l.comwrote in message
news:eX******** ******@TK2MSFTN GP02.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.GetN umberOfUsersOnl ine().

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*******@gmai l.comwrote in message news:%2******** ********@TK2MSF TNGP02.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.comwrot e in message
news:%2******** ********@TK2MSF TNGP06.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 GetNumberOfUser sOnline();
Declaring Type: System.Web.Secu rity.Membership

Use Lutz Roeder's Reflector to look up System.Web.Secu rity.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**@markNOSPA Mrae.netwrote in message news:%2******** *******@TK2MSFT NGP02.phx.gbl.. .
"Juan T. Llibre" <no***********@ nowhere.comwrot e in message news:%2******** ********@TK2MSF TNGP06.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.comwrot e in message
news:eX******** ******@TK2MSFTN GP03.phx.gbl...
re:
!Really..? How does it know...?

It keeps track of them with :

public static int GetNumberOfUser sOnline();
Declaring Type: System.Web.Secu rity.Membership

Use Lutz Roeder's Reflector to look up System.Web.Secu rity.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**@markNOSPA Mrae.netwrote in message news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
"Juan T. Llibre" <no***********@ nowhere.comwrot e in message news:eX******** ******@TK2MSFTN GP03.phx.gbl...
>re:
!Really..? How does it know...?

It keeps track of them with :

public static int GetNumberOfUser sOnline();
Declaring Type: System.Web.Secu rity.Membership

Use Lutz Roeder's Reflector to look up System.Web.Secu rity.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.comwrot e in message
news:%2******** ********@TK2MSF TNGP04.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3131
by: mr_burns | last post by:
hi, i am wanting to count the number of unique rows under a certain column. i want to count how many times a page has been accessed. how i plan to do this is every time a page is accessed, a session id variable is checked for. if noe exist, a piece of code will create on. then the session id is store in a table under one column and the pages pre-defined number will be stored under another. so if i want to check how many users have access...
3
2174
by: A Seel | last post by:
COUNTING NUMBER OF SELECTS MADE table mytable { id, data, hits }
4
17624
by: Tim Morrison | last post by:
SQL Server 2000 - MSDE 2000 Is there a way to get the number of current users logged into a SQL 2000 Server (also MSDE)? Cant be distinct users as most users are logged into the database using the same login. -- Tim Morrison -------------------------------------------------------------------------------- Vehicle Web Studio - The easiest way to create and maintain your vehicle related website.
1
1902
by: Sourabh | last post by:
Hello, I am trying to write a VB.NET monitoring application for a MS SQL server. For that I need to know the following: 1. How do I count the number of read/write accesses per database on the server since the creation of the DB? 2. How do I get the last access time of the database ? Any inputs would be really appreciated.
2
1803
by: Lenn | last post by:
Hello, This requirement might seem strange to someone out there, but here it's We need to make sure only certain number of users can be logged in the site at the same time. Is there any way to do that in ASP.NET, in web config file or otherwise. Thanks in advance for your help.
5
4003
by: jjw | last post by:
I have a website that requires users to login. We track them by using sessions. We record the time and date that they login, their session id, the last page they visited, etc in a database. As as admin, I would like to be able to login and force a logout of other users logged in. Is this possible? I have looked online but there doesn't seem to be any information that addresses this.
6
15422
by: krvrk | last post by:
Hi, I am creating a report for which i need to query a table for total number of users and Concurrent users logged in. The table will contain Username(nvarcar,not null),SessionStart time(datetime, not null), SessionEnd time (datetime,null), SessionID(int,not null) and ConnectGUID(uniqueidentifier, not null) etc can any one help me in finding total and number of concurrent logins per day. Sample Data
3
9260
by: RogueIT | last post by:
Is there a way in 2005 to tell what user is logged into what database on the SQL Server? thanks, Scott
3
3451
by: raghunath1981 | last post by:
Hi All, Could you please help me with writing a sql for counting number of times a varchar (1000) repeated in the table. I think I cannot use groupby/distinct etc. Please give me an idea how I could do that if I want the output such that each row is the varchar (distinct) and number times it repeated. I was trying several things but it did not work :( select tab1.varchar_col , tab2.CNT from tab tab1 ( select count(*) from tab group...
0
8987
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8826
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9534
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9241
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8239
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2777
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.