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}