Hi friends,

How to Find the no of simultaneous users logged in to a web site at a time?.

Any help with the C# code will b greatly appreciated.

Regards

Robins

Dani AI

Generated

Define what "simultaneous users logged in" means (authenticated accounts with recent activity, active sessions, or concurrent TCP connections). A reliable approach is to treat "logged in" as accounts with a recent server-side heartbeat and record a last-activity timestamp for each authenticated user. This avoids guessing from page hits or open sockets.

As suggested, a simple file counter is possible but brittle (race conditions, process crashes, no cleanup). As noted, IIS logs and analytics give useful traffic/peak estimates but do not prove who is currently authenticated. Prefer one of these patterns:

  • Single-server, simple: use a thread-safe in-memory map keyed by user id with last-activity timestamps; update on login and on each request (or via heartbeat). A periodic cleanup or TTL window yields the current count.
  • Web-farm / durable: record logins/heartbeats to a central store (SQL, Redis, etc.). Use TTL or background jobs to expire idle entries so the count stays accurate across servers.
  • Real-time UI: push counts with SignalR or WebSocket so dashboards update immediately.
  • Monitoring only: use IIS logs or PerfMon counters for historical/peak analysis.

Do not rely on Global.asax Session_End for general tracking: Session_End fires only for InProc session-state and will not work reliably with out-of-process session modes or in web farms (). Keep implementation atomic, handle logout and abrupt disconnects via timeouts, and choose a storage solution that matches the app topology (in-memory for single process, distributed store for many servers).

Recommended Answers

All 2 Replies

Hi friends,

How to Find the no of simultaneous users logged in to a web site at a time?.

Any help with the C# code will b greatly appreciated.

Regards

Robins

Is this for a website of yours? Or just in general? If it is yours, then when you run the script for loggon (probably php) have the script update a file with an incremented number of users, and conversely decrement it when someone logs off. Then if you choose to use C#, have it open this file and read the number...

There's any number of ways you can do this-- if you're not actually keeping track of users logged into the site, you can really only track things through IIS, like page hits per hour, etc, with some type of analytics software.

How are you keeping track of when users log in?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.