application| Objects | tutorials
A set of ASP files that work together to accomplish a task are called Applications (application). The Application object in ASP is used to bundle these files together.
Application objects
An application on the Web can be a set of ASP files. These ASP files work together to accomplish a task. The Application object in ASP is used to bundle 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 a Application object, while the session object and the user's relationship are one by one corresponding.
The Application object holds information (such as database connection information) that will be used by many pages in the application. This means that the information can be accessed from any page. It also means that you can change the information somewhere, and then the changes will be automatically reflected on all the pages.
Storing and retrieving application variables
Application variables can be changed by any page in the application.
You can create a application variable like this in "Global.asa":
<script language= "VBScript" runat= "Server" >sub application_onstartapplication ("vartime") = "" Application (" Users ") =1end sub</script>
In the example above, we created two application variables: "Vartime" and "users."
You can access the value of the application variable like this:
There are <%response.write (Application ("users"))%> active connections.
Loop Traversal Contents Set
The contents set contains all the application variables. We can view the variables stored in it by traversing the contents set:
<%dim IFOR each I in application.contents Response.Write (i & "<br/>") next%>
If you don't know the number of items in the contents set, you can use the Count property:
<%dim Idim jj=application.contents.countfor I=1 to J Response.Write (Application.Contents (i) & "<br/> ") next%>
Loop Traversal StaticObjects Set
You can iterate through the StaticObjects set to see all the values stored in the Application object:
<%dim IFOR each I in application.staticobjects Response.Write (i & "<br/>") next%>
Lock and Unlock
We can use the "lock" method to lock an application. When the application is locked, the user cannot change the application variable (except the user who is accessing the application variable). We can also use the "Unlock" method to unlock the application. This method removes the lock on the application variable:
<%application.lock ' Do some Application object operationsapplication.unlock%>