Srikanth Venugopalan
Srikanth Venugopalan

Reputation: 9049

Get number of concurrent users online - ASP.NET

I would like to know the number of users logged into my ASP.NET 2.0 application.

Points to be considered: 1) Simplest way would be to use Application or Cache object to have the counts on Session start or end. However this would fail if there is a worker process recycle. Wouldn't it?

2) Should't make a difference whether the session is inproc/state server managed/ or SQL server managed.

3) Should preferably be seamless to a web-farm architecture.

Upvotes: 1

Views: 14758

Answers (3)

Dean Harding
Dean Harding

Reputation: 72658

If you use the built-in ASP.NET membership provider, then there's the ever-so-handy Membership.GetNumberOfUsersOnline() method.

(Of course, it only works authenticated users...)

Upvotes: 6

Raj Kaimal
Raj Kaimal

Reputation: 8304

ASP.Net comes with several performance counters

http://msdn.microsoft.com/en-us/library/fxk122b4.aspx

State Server Sessions Active The number of currently active user sessions. This counter is available only on the computer where the state server service (aspnet_state) is running.

Requests/Sec The number of requests executed per second. This represents the current throughput of the application. Under constant load, this number should remain within a certain range, barring other server work (such as garbage collection, cache cleanup thread, external server tools, and so on).

Upvotes: 1

TheGeekYouNeed
TheGeekYouNeed

Reputation: 7539

You should store a user's online status in a database. Each time a page is navigated, their LastActivity information (in the database table) is updated.

Create a SQL job that runs and logs users off if there is X amount of inactivity (and of course, if they actually do hit logout, update the database to mark the user offline)

Upvotes: 0

Related Questions