Author: scholar
In the previous article, the author introduced in detail how to use ASP built-in object Response, in this article, the author will continue to introduce the other two very practical and important ASP built-in objects Application and Session.
In addition to the objects used to send, receive, and process data, ASP's built-in objects also have some very useful objects that represent the Active Server application and individual user information.
Let's take a look at the Application object. All. asp files in the same virtual directory and its subdirectories constitute ASP applications. Instead of using the Application object, we can share information among all users of a given Application and persistently save data during server running. In addition, the Application object also provides methods to control access to Application layer data and events that can be used to trigger the process when the Application starts or stops.
Next let's learn the Application object together.
1. Although the pplication object does not have A built-in attribute, we can use the following syntax to set A user-defined attribute, which is also called A set.
A pplication ("attribute/set name") = value
We can use the following script to declare and create the attributes of the Application object.
<% Application ("MyVar") = "Hello" Set Application ("MyObj") = Server. createObject ("MyComponent") %> once we assign the attribute of the ication object, it will persist until the w eb server service is disabled to stop A pplication. Because the values stored in the pplication object can be read by all users of the application, the attribute of the pplication object is particularly suitable for transmitting information between users of the application.
2. There are two methods for the method Application object. They are used to process the data written by multiple users in the Application.
1. L The ock method prohibits other customers from modifying the properties of the supply object.
The Lock method prevents other customers from modifying the variables stored in the Application object to ensure that only one customer can modify and access the Application variables at the same time. If you do not explicitly call the Unlock method, the server will Unlock the Application object after the. asp file ends or times out.
Let's take A look at the following program that uses A pplication to record page access times: <% Dim NumVisitsNumVisits = 0 Application. lockApplication ("NumVisits") = Application ("NumVisits") + 1 Application. unlock %> Welcome to this page. You are the <% = Application ("NumVisits") %> guest on this page! Save the above script in your. asp file, and easily add a counter to your page.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service