Learn ASP.NET - APPLICATION Status

zhaozj2021-02-16  159

Learning ASP.NET - APPLICATION Status Nickcheng

Everyone knows that in ASP.NET, the connection between the browser and the web server is the so-called "stateless connection". The entire connection process is as follows:

1. Connect to the server 2, tell the server accessient I want to access the content 3, the server returns the contents required by the visitor 4, and the server is disconnected while losing all user information

This is the case, we will use Application, Cookie, Session these things to achieve the purpose of saving specific user information, in this article, we are going to talk about Application.

The principle of Application is to create a status variable on the server side to store the required information. It should be noted that first, this status variable is built in memory, followed by this status variable to be accessed by all the page of the website. This means that it can only store some information to be published, and cannot store some personal information!

Let's take a look at one example:

//test1.aspx<%@Page language = "c #"%> <% application ["companytelephone"] = "123456789";%> Application State Changed SuccessFully

-------------------------------------------------- ------------

//test2.aspx<%@ page language = "c #"%> company telephone = <% response.write (Application ["Companytelephone"]);%>

P.s. The above is two files to be established separately.

Call the Test1.aspx file in the browser, you will see the display in your browser:

Application State Changed SuccessFully

This means that we have successfully established an Application status. Then, call the Test2.aspx file, then you can see the results we want:

Company telephone = 123456789

What is seen above is the general situation of using the Application status. Have you ever thought about other situations? For example, when you have successfully established the Application State (TEST1.ASPX), the server suddenly dispensses or is restarted.

This is coming so. If you really have the above situation, then we will not see the results we want after running Test2.aspx. So in order to avoid the above case, we should configure the application status when starting the website. We should use the Global.asax file here.

//global.asax