Limit the number of users accessing the asp.net website

What is the best way to limit the number of (simultaneous) users accessing a web application that anyone can submit to sell a website / application to a client and how to increase the number of users accessing it remotely?

+4
source share
3 answers

If you use session state management in the process, you can use the HttpApplicationState class by entering the Global.asax file and putting something like this in the code behind:

void Application_Start(object sender, EventArgs e) { Application["ActiveSessions"] = 0; } void Session_Start(object sender, EventArgs e) { try { Application.Lock(); int activeSessions = (int) Application["ActiveSessions"] + 1; int allowedSessions = 10; // retrieve the threshold here instead Application["ActiveSessions"] = activeSessions; if (activeSessions > allowedSessions) System.Web.HttpContext.Current.Response.Redirect("~/UserLimitReached.aspx", false); } finally { Application.UnLock(); } } void Session_End(object sender, EventArgs e) { Application.Lock(); Application["ActiveSessions"] = (int)Application["ActiveSessions"] - 1; Application.UnLock(); } 

Then in UserLimitReached.aspx you call HttpSession.Abandon () to effectively end the current session so that it is not taken into account to the limit. You will have to figure out the rest yourself. :)

+6
source

One way is to track active sessions in the database, and each time a user logs in, it checks the number of active sessions. If it is below the threshold value, let them, if not, refuse them.

To remotely manage this number, a simple administrator form that allows you to update the threshold in the database is quite simple.

0
source

In addition to the previous answers, I think you will need to enter your own timeout so that the sessions do not remain prolonged and blocked. Instead of using sessions, if you have a login, you can track it based on logins and keep them active, recording the latest activity for each user in a dictionary / array. This should help you understand which users are using the site and which are the last active users. If you associate this with sessions, you can end the sessions used by the last active user. The effect of this is that if more than the specified number of users tries to use the website, some (the least active) will constantly need to register. Given the incoherent nature of web applications, I think you might have to allow a certain percentage of grace, so if it is limited to 20 users, you will actually allow, maybe 22 to be active at the same time.

0
source

All Articles