Programming in a Web application, when a user accesses the application, the session-type variable allows the user to share data in all pages of the Web application, and if another user also accesses the Web application, he has his own session variable, However, two users cannot share information through session variables, while variables of the application type can be used to share information among multiple users of a site across all pages. You can understand that the session is a local variable, and application is a global variable.
All. asp files in the same virtual directory and its subdirectories make up the ASP application. Instead of using the Application object, we can share information between all users of a given application and persist the data during the server's run. Also, the Application object has control over how the application-tier data is accessed and the events that can be used to trigger the process when the application starts and stops.
First, Application ("name") =value
As with the session ("name") =value, the Application object also has no built-in properties. Of course, users can customize attributes, which can also be called collections.
Once the properties of the Application object are assigned, it persists until the Web Server service is turned off so that application stops. Because the values stored in the Application object can be read by all users of the application, the properties of the Application object are particularly suitable for passing information between users of the application.
<%application ("myname") = "Cnbruce"%>
Second, Application.Lock
The lock method prevents other users from modifying the properties of the Application object to ensure that only one customer can modify and access the application variable at the same time. If the user does not explicitly call the Unlock method, the server will unlock the Application object after the. asp file finishes or times out. The simplest is an example of a page count.
1,num.asp
<%application.lockapplication ("numvisits") = Application ("NumVisits") + 1application.unlock%>
You are the <%=application ("NumVisits")%> visitor to this page.
The above program, you will find that every time you refresh, you will count the cumulative, such as access to the IP value to count, then establish a session.
2,vnum.asp
<%if session ("visitnum") = "" Thenapplication.lockapplication ("numvisits") = Application ("NumVisits") + 1application.unlocksession ("visitnum") = "visited" End if%>
You are the <%=application ("NumVisits")%> visitor to this page.
Third, Application.UnLock
In contrast to the lock method, the Unlock method is to allow other users to modify the properties of the Application object. As can be seen in the example above, the Unlock method unlocks the object so that the next client can increase the value of the numvisits.
Of course, it should be noted that the number to ensure that the server is not restarted, because so the access is the number is based on the page, not to save the file or save to the database such processing.
Typically, a application event is triggered when the server restarts.
Four, Application_OnEnd
The Application_OnEnd event occurs after the Session_OnEnd event when the application exits, and the process of Application_OnEnd events must also be written in the Global.asa file.
For example, in the above program, if the server shutdown is bound to trigger the Application_OnEnd event, then the event can be data-saving work, has made the next data to continue along.
Of course, the Application_OnEnd event occurs after the Session_OnEnd event when the application exits.
<script language= "VBScript" runat= "Server" .... ..... Sub application_onend ....... End Sub .............</script>
Five, Application_OnStart
The Application_OnStart event occurs before the first time a new session (that is, a Session_OnStart event) is created. The Application_OnStart event is triggered when the Web server starts and allows requests for files that are contained by the application.
<script Language=scriptlanguage The Runat=server> of the ..... Sub Application_OnStart ....... End Sub.............</script>
So now you can imagine the code inside the global.asa
<script language= "VBScript" runat= "Server" >sub application_onstart ............ End Sub Sub Session_OnStart ............. End Sub Sub Session_OnEnd ............. End Sub Sub application_onend ............. End Sub </SCRIPT>