What would be a good way to restrict an ASP.NET web application to only serve a given ammount of concurrent users?
Some requirements are:
- Application requires login (no need to worry about anonymous users).
- Multiple servers support (farm / load balancing).
- An active user can be considered to be the same as an active session (not signed off or expired).
- Additional logins must be denied if the maximum number of concurrent users has been reached.
- Accountability is needed (administrators should be able to see who the active users are).
- Minimum overhead on each web request (especially avoiding costly trips to a database on each request).
- Total number of concurrent users should be kept correct even if a web server hangs, disconnects from network or has to be restarted.
- Additional servers are available to host services (e.g. application servers).
You could use a global variable (static) and hook up the logic in your Application_OnStart, Application_BeginRequest, or Page_Load events. Check out this for more an example: http://dotnetperls.com/global-variables-aspnet