Reference article: Online count of login authentication for ASP. NET MVC3.0 website
Reference article: Web site Traffic statistics method code in ASP
Global Code:
protected voidApplication_Start () {application["Online"] =0;///Initialize the number of people online at the first start of the application 0Arearegistration.registerallareas (); Routeconfig.registerroutes (routetable.routes); Log4net. Config.XmlConfigurator.ConfigureAndWatch (NewFileInfo (Server.MapPath ("/configs/log4net.config"))); } protected voidSession_Start (Objectsender, EventArgs e) { //get the visitor's IP, get the source of the visitorCommon. Sysinfo.sessionlog (request.servervariables["REMOTE_ADDR"], request.urlreferrer); //Lock VariableApplication.Lock (); application["Online"] = (int) application["Online"] +1;//online number plus +1//UnlockApplication.UnLock (); } protected voidSession_End (Objectsender, EventArgs e) { //The code that runs at the end of the session. //Note: The Session_End event is raised only if the sessionstate mode in the Web. config file is set to InProc. If the session mode is set to StateServer//or SQL Server, the event is not raised. //Lock VariableApplication.Lock (); application["Online"] = (int) application["Online"] -1;//online number plus +1//UnlockApplication.UnLock (); }
Introduction to ASP. NET MVC Programming--Website Access statistics