Know who is online ?

S

Steph

Hi,

I would like to be able to know who is actually connected on the website i
am creating.
The users are stored in a sql server table (to enter, they have to be
identified on the login.aspx page...)

I guess i have to use application variables and global.asax, but i don't
know exactly how to do this...

Thanks !
 
D

David Lozzi

Hi

You would want to do something like this in your login file

After verification and session is loaded with user info

Application("TotalConnected") += 1
Application("UserNames") &= username & "," ' you need a delimiter to be
able to split later on

Then to display this info, simply split the Application("UserNames") on ','
and you'll have a list. Don't forget to include the removal of their names
at log off:

In global.asax do something like this

On SessionEnd()
Application("TotalConnected") -= 1
Application("UserNames") =
replace(Application("UserNames"),session("username") & ",", "") ' or
something like that

NOTE: The session end will fire when you call a session.abandon in your
logout scripts, however if a user just closes their browser, I beleive it
will take 20 minutes, or whatever the timeout is set to on the server, for
the session to expire. At this point I do not know if it will fire the
SessionEnd function. Can someone else input on this?

Enjoy!

David Lozzi
 
P

Patrice

You could keep the date/time of the last HTTP request made by a particular
user. You could then consider that those who made a request within the last
X minutes are online...

This would be my personal preference over using the session end event (that
have its own timeout, thay may not work depending on the session provider
plus perhaps not always fire for example in case of a crash).

Patrice
 
D

David Lozzi

Interesting, so what you're saying is collect the user's last HTTP request
and store it in the application state? So something like that would have to
be in every page to collect the information right, like in a usercontrol or
something?
 
P

Patrice

Yes something similar (I meant of course storing just the date/time of the
last request possibly by user).

This way you'll be able :
- to consider that online users are those that made something within the
last 5 minutes (while you can still have session_end firing 20 minutes by
default after the last action)
- you could also have their names (it looks like from the question you were
interested not only in how many but also on "who" exactly)

It also depends on what is your definition of an "online" user and hows much
user you expect at the same time (you could remove from time to time expired
informations).

You should be able to do that at the beginning of each request (using
global.asax) instead of adding this explictely on each and every page.

Patrice

--
 

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
474,265
Messages
2,571,069
Members
48,771
Latest member
ElysaD

Latest Threads

Top