ASP Application Object
- Previous Page ASP Session
- Next Page ASP #include
A set of ASP files that work together to complete a task is called an application (application). The Application object in ASP is used to bind these files together.
Application object
A web application on the web can be a set of ASP files. These ASP files work together to complete a task. The Application object in ASP is used to bind these files together.
The 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, while the session object is one-to-one corresponding with users.
The Application object contains information that is used by many pages in the application (such as database connection information). This means that these information can be accessed from any page. It also means that you can change these information at one location, and the changes will automatically reflect on all pages.
Store and retrieve Application variables
Application variables can be accessed and changed by any page in the application.
You can create Application variables like this in "Global.asa":
<script language="vbscript" runat="server"> Sub Application_OnStart application("vartime")="" application("users")=1 End Sub </script>
In the above example, we created two Application variables: "vartime" and "users".
You can access the value of the Application variable like this:
<% Response.Write(Application("users")) %>
Iterate over the Contents collection
The Contents collection contains all application variables. We can iterate over the contents collection to view the variables stored within:
<% dim i For Each i in Application.Contents Response.Write(i & "<br />") Next %>
If you are not clear about 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 %>
Iterate over the StaticObjects collection
You can iterate over the StaticObjects collection to view the values of all objects stored in the Application object:
<% dim i For Each i in Application.StaticObjects Response.Write(i & "<br />") Next %>
Lock and unlock
We can use the "Lock" method to lock the application. After the application is locked, users cannot change the Application variable (except for the user currently accessing the Application variable). We can also use the "Unlock" method to unlock the application. This method will remove the lock on the Application variable:
<% Application.Lock 'do some application object operations Application.Unlock %>
- Previous Page ASP Session
- Next Page ASP #include