Using ASP. Application object to realize the function of online demographics

Source: Internet
Author: User

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 (); } &LT;/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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.