ASP. NET

Source: Internet
Author: User

In large websites, we often need to count the number of visitors to the website, and adjust the Cache Policy access policy based on the number of visitors to the website.

1. Create a website and apply it globally to the websiteProgramThe application_start () method in the class records the number of visitors to the static variable,CodeAs follows:

1Public Static Int_ Totalcount;2VoidApplication_start (ObjectSender, eventargs E)3 {4//Code that runs when the application starts5_ Totalcount =0;6}

2. In the session_start () method of the global application class, the lecture records the total number of visitors. 1:

1VoidSession_start (ObjectSender, eventargs E)2 {3//Code that runs when a new session is started4 Application. Lock ();5_ Totalcount ++;6 Application. Unlock ();7}

3. Add the total number of visitors to the page_load event handler on the test page:

1Protected VoidPage_load (ObjectSender, eventargs E)2 {3This. Response. Write (String. Format ("Current website visits: <B >{0} </B>", Global. _ totalcount ));4}

 

 

 

 

 

 

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.