ASP built-in object of the Application object

Source: Internet
Author: User
application| Objects | Built-in Objects | The Application object is an application-level object that is used to share information among all users and to persist data over time while the Web application is running.
Properties of application:
The method is as follows:
The Application object has no built-in properties, but we can create its own properties.
<% Application ("property name") = value%>
In fact, most application variables are stored in the Contents collection, and when you create a new application variable, you actually add an item to the Contents collection. The following two scripts are equivalent:
<% Application ("greeting") = "hello!"%> or <% application.contents ("greeting") = "hello!" Because the application variable exists in the collection, if you want to show it all, the method we have used many times, such as for Each loop.
<%
For each item in Application.Contents
Response.Write ("<br>" &item&application.contents (item))
Next
%>
The Application Method:
There are only two methods for application: One is lock and the other is unlock. Where the lock method is used to ensure that only one user can operate on the application at the same time. Unlock is used to cancel the lock method limit. Such as:
<%
Application.Lock
Application ("Visitor_num") =application ("Visitor_num") +1
Application.UnLock
%>
Application events:
1, Application_OnStart ()
triggered when an event application is started.
2, Application_OnEnd ()
Triggered at the end of this event application.
Both of these event procedures must be defined in the global.asp file, typically defining the function of the connection data in both events and then placing them in the global.asp. For example:
Sub Application_OnStart
Application ("tt18_connectionstring") = "Driver={sql
server};server=jeff;uid=sa;pwd=;d Atabase=test "
End Sub
An array can be defined as a Application object, but the array can only be saved as an object and not application (0) to fetch its value. You can define a temporary array to implement this functionality. Such as:
<%
Dim Array ()
Array=application ("array")
For i = 0 To UBound (array)
Response.Write Array (i)
Next I
%>
You can also modify the Application object to define a temporary array, assign the application object to the array, modify the elements of the array, and finally assign the array back to the Application object. Such as:
<%
Dim Array ()
Array=application ("array")
Array (0) = "Jeff"
Array (1) = "Zhu"
Application.Lock
Application ("array") =array
Application.UnLock
%>

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.