Note: Recently in Review ASP , in order to deepen the impression, will make some small Demo program, share to everyone.
1 Create a new ASP . NET Web site, edit the Global.asax file, and the modified file contents are as follows.
<%@ application Language= "C #"%> <script runat= "Server" > void Application_Start (object sender, EventArgs E {//code run at application startup application["Currentusercount"] = 0; } void Application_End (object sender, EventArgs e) {//code to run at application shutdown} void application _error (object sender, EventArgs e) {//code to run in the event of an unhandled error} void Session_Start (object sender, EventArgs e) {//code Application.Lock () running at the start of a new session; application["Currentusercount"] = (int) application["Currentusercount"] + 1; Application.UnLock (); } void Session_End (object sender, EventArgs e) {//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. Application.Lock (); application["Currentusercount"] = (int) application["Currentusercount"]-1; Application.UnLock (); } </script>
2 Modify the Web. config file, add the following configuration node, new configuration node bits <system.web></system.web> nodes.
<sessionstate mode= "InProc" timeout= "1" cookieless= "false"/>
3 Add a label to the Default.aspx file to display the current number of people online.
protected void Page_Load (object sender, EventArgs e) {this . Label1.Text = application["Currentusercount"]. ToString ();}
4 use IE and Chrome browser to access the application, get the results shown.
Using ASP. Application object to realize the function of online demographics