Latest web development tutorials

ASP Application Object

Work together to accomplish a task group ASP file called an application.


Application Object

An application on the Web may be a group of ASP files. The ASP files work together to accomplish a task. The ASP Application object is used to put these files bundled together.

Application object is used to store and access variables from any page, similar to the Session object. The difference is that all users share one Application object, Session object and user relationship is one to one.

Application objects there will be a lot of information in the application page uses (such as database connection information). You can access this information from any page. And you can also change the information in one place, then those changes will be automatically reflected on all pages.


Store and retrieve variables Application

Application variables can be any page in the application to access and change.

You can create Application variables in "Global.asa", as follows:

<script language="vbscript" runat="server">

Sub Application_OnStart
application("vartime")=""
application("users")=1
End Sub

</script>

In the example above, we create two Application variables: "vartime" and "users".

You can access the value of the Application variable, as follows:

There are
<%
Response.Write(Application("users"))
%>
active connections.


Traversal Contents collection

Contents collection contains all application variables. You can traverse the Contents collection, to see which stores variables:

<%
dim i
For Each i in Application.Contents
Response.Write(i & "<br>")
Next
%>

If you do not know the number of items in the Contents collection, you can use the Count property:

<%
dim i
dim j
j=Application.Contents.Count
For i=1 to j
Response.Write(Application.Contents(i) & "<br>")
Next
%>


Traversal StaticObjects collection

You can traverse StaticObjects collection, to see the values ​​of all objects stored in the Application object:

<%
dim i
For Each i in Application.StaticObjects
Response.Write(i & "<br>")
Next
%>


Locking and unlocking

You can use the "Lock" to lock the application method. When an application is locked, users can not change the Application variables (except the user is accessing the Application variable). You can also use the "Unlock" to unlock the application method. This method removes the lock on the Application of variables:

<%
Application.Lock
'do some application object operations
Application.Unlock
%>