How to count the active sessions

How to count the active sessions

Is it possible to count the current active sessions in an application ?

And if so, is it possible to have (and how) :
- the active not logged in amount(count) 
- the active logged in amount(count) 
Hi Joop,

I remember doing something similar sometime ago (for .NET stack). We first mapped the ASPState catalog table that contains the current .NET session IDs. Doing a count over this table should give you the current active sessions (for all .NET applications).

To know which ones are logged in in the platfrm and those that are not, a quick way is to join the above table with the screen log tables. These tables contain ASP Session ID and UserId. Please note: this is really bad performant, though! Screen log system entities are views, remember...and doing a join from different catalogs will require the DBMS to scan both sources entirely. For this reason I'd prefer a separate model: make your own entity User_Session that stores the UserId and ASP Session ID.

Let me know if this worked for you,

...also, HTTPRequestHandler may help you retrieving the current HTTPRequest's ASP.NET Session ID.
If I create my owne User_Session table I can store the ID on onSessionStart ... however if a user has a timeout (inactive for a while) the entry is still in the table ... And I want to get rid of that one then :-)
How do I do this ? in ASP I have more control over the session object (grin)
Hi Joop,

For following that approach, you'd have to update a timestamp whenever the user accessed a page (you'd probably want to setup this in your layout / master page, for keeping it in one place).

When counting the nr of sessions, you'd take into account only those updated on the last 20 minutes (depending on your session timeout).

A timer running periodically could purge old records from this table.

Yes, you'll just have to use the performance counters:

In fact, you can get *lots* of system performance data that way:

You'll need an extension to run the custom .NET code.
In the meantime, I've figured this one out with help of Brian Hollander ..

I have a table Online:
LastPage -> GetPageName(),
LastIp -> GetIP(),
OnlineStart (datetime) 
OnlineLast (datetime)

Using the OnSessionStart and BeginWebRequest actions to fill/update this.
Also in the BeginWebRequest I clear entries inactive for 20 minutes
Thanks for sharing, Joop! Just curious, how many users does your application have?
How fast are those updates, on each request?
App 100 users,  app 5 concurrent
Yes on every request ... pretty fast :-)

it's for a forum (grin)