Analysis of Application Global Object Usage Example in ASP. NET

  • 2021-07-01 07:07:27
  • OfStack

This article illustrates the use of the Application global object in ASP. NET. Share it for your reference. The details are as follows:

Application is an application global object, which is shared by all. Application information can be read on the other page, regardless of which page is used to operate Application.

Since Application is shared, Lock precedes the operation and UnLock after the operation is completed.

Set up data on 1 page:


Application.Lock(); 
Application.Set("address", " Shanghai "); 
Application.UnLock(); 

Fetch data on another page:


string s = (string)Application.Get("address"); 
Button1.Text = s; 

Add a "global application class" Global. asax, which is executed when the first page of the application is accessed by Application_Start.

Take the example of "counting the number of visitors", which is rotten by many books. Application_BeginRequest will execute the number + + every time a content is accessed on the server. Why is this not good? Large concurrent access will be very card!

Here to note: do website development try not to use Application, also rarely need to use it.

I hope this article is helpful to everyone's asp. net programming.


Related articles: