1, the site initiates the initialization of the online number of variables
application["websitecount"0;
2. New sessions come in
This method executes only when a new session comes in. Can filter out some of the unnecessary, restricted pages, such as the background management system of the page, in the background when the user does not participate in restricting the number of people, so that even after entering the background to access other pages will not trigger the Session_Start method.
Session.Abandon (); indicates that deleting the current session object will trigger the Session_End method.
protected voidsession_start (Object sender, EventArgs e) {application.lock (); application["Websitecount"] = (int) application["Websitecount"] +1; Application.UnLock (); if(! Request.RawUrl.Equals ("/login.aspx", StringComparison.OrdinalIgnoreCase) &&application["Websitecount"] !=NULL&& Convert.ToInt32 (application["Websitecount"]) >count) {Session.Abandon (); Response.Redirect ("503.html"); } }
3, session end, service end session expired
protected void Session_End (Object sender, EventArgs e) { application.lock (); application["websitecount"] = (int) application[" Websitecount"1; Application.UnLock (); }
ASP. NET Online number limit