Advanced ASP Programming (9)

Source: Internet
Author: User
In a Web application, when a user accesses the application, the Session type variable allows the user to share data on all pages of the Web application; if another user accesses the Web application at the same time, the user also has his own Session variables, but the two users cannot share information through the Session variables, application-type variables allow multiple users on the site to share information across all pages. It can be understood that Session is a local variable, while Application is a global variable.
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.
1. Application ("name") = value
Just like Session ("name") = value, the Application object does not have any built-in attributes. Of course, you can customize an attribute, which is also called a set.
Once an Application object is assigned a property, it will persist until the WEB server service is disabled to stop the Application. Because the values stored in the Application object can be read by all users of the Application, the attributes of the Application object are especially suitable for transmitting information between users of the Application.
<% Application ("MyName") = "cnbruce" %>
II. Application. Lock
The Lock method prohibits 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 you do not explicitly call the Unlock method, the server will Unlock the Application object after the. asp file ends or times out. The simplest example is the page count.
1, num. asp
<% Application. LockApplication ("NumVisits") = Application ("NumVisits") + 1Application. Unlock %>
You are the <% = Application ("NumVisits") %> visitor on this page.
In the above program, you will find that every refresh will accumulate the number of records. For example, if the number is accessed by IP value, a Session will be created.
2. vnum. asp
<% If session ("visitnum") = "" thenApplication. lockApplication ("NumVisits") = Application ("NumVisits") + 1Application. unlocksession ("visitnum") = "visited" end if %>
You are the <% = Application ("NumVisits") %> visitor on this page.
Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.