Asp Built-in Object Application Detailed Description
In addition to the objects used to send, receive and process data, there are some very practical objects representing ActiveServer applications and individual user information in ASP.
Let's take a look at the Application object first. All .asp files in the same virtual directory and its subdirectories constitute the ASP application. Instead of using Application objects, we can share information among all users of a given application and save data persistently during server operation. Furthermore, the Application object also has methods for controlling access to application-level data and events that can be used to trigger a process when an application starts and stops.
Let's learn about Application objects together.
1. Attributes
Although the Application object does not have built-in properties, we can set user-defined properties using the following syntax, which can also be called collections.
Application("Property/Collection Name")=Value
We can declare and create properties of the Application object using the following script.
<%
Application("MyVar")="Hello"
SetApplication("MyObj")=Server.CreateObject("MyComponent")
%>
Once we assign the properties of the Application object, it persists until the WEB server service is shut down so that the Application stops. Since 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.
2. Method
There are two methods for Application objects, both of which are used to handle the problem of multiple users writing data stored in Application
1. The Lock method prohibits other customers from modifying the properties of the Application object.
The Lock method prevents other customers from modifying variables stored in the Application object to ensure that only one customer can modify and access the Application variables 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 ends or timeouts.
Let's take a look at the following program that uses Application to record the number of page accesses:
<%
DimNumVisitsNumVisits=0
Application.LockApplication("NumVisits")=Application("NumVisits")+1
Application.Unlock
%>
Welcome to this page, you are the <%=Application("NumVisits")%> visitor on this page!
Save the above script in your .asp file and add a counter to your page easily.