First, open vitualstudio2010, create a new Web site, then add new items, create a new login.aspx and Index.aspx page. Add a new item, select the Global application class, and the page is global.asax.
First step: Open the Global.asax page and write the following code under the Application_Start () method:
Application.Lock ();
application["Count"]=0; Application.set ("Count", 0)/application.add ("Count", 0) initializes the variable, which is equivalent to setting count to 0.
application["Online"]=0;
Application.UnLock ();
Step Two: Write the following code in the Session_Start () method:
Application.Lock ();
Session.Timeout (1); Setting a session to a time of one minute, or no action within a minute, will invalidate the session.
application["Count"]= (int) application["Count"]+1;
application["Online"]= (int) application["online"]+1;
Application.UnLock ();
Step three: Write the following code in the Session_End () method:
Application.Lock ();
Session.Abandon (); When you end a session, log off the session
application["Online"]= (int) application["online"]-1;
Application.UnLock ();
Fourth step: Write the following code in Index.aspx.cs's Page_Load () method:
Response.Write ("<br/> Total number of visitors:" +application["Count"]. ToString ());
Response.wrirte ("<br/> is currently online": "+application["). ToString ());
The total number of visitors to the output and the number of people currently online can also be output through a Label control or other control, such as:
label1.text=application["Count"]. ToString () + "person"
label2.text=application["Online"]. ToString () + "person"
C # Statistics website total number of visitors and current online application