ASP Application Object
- Previous Page ASP Session
- Next Page ASP #include
Een set ASP-bestanden die samenwerken om een taak uit te voeren wordt genoemd toepassing (application). Het Application-object in ASP wordt gebruikt om deze bestanden samen te binden.
Het Application-object
Een toepassing op het web kan een set ASP-bestanden zijn. Deze ASP-bestanden werken samen om een taak uit te voeren. Het Application-object in ASP wordt gebruikt om deze bestanden samen te binden.
Het Application-object wordt gebruikt om variabelen van elke pagina op te slaan en te benaderen, vergelijkbaar met het session-object. Het verschil zit erin dat alle gebruikers een Application-object delen, terwijl het session-object een een-op-een relatie heeft met de gebruikers.
Het Application-object bevat informatie die door vele pagina's in de applicatie wordt gebruikt (bijvoorbeeld databaseverbindinginformatie). Dit betekent dat deze informatie van elke pagina kan worden benaderd. Het betekent ook dat je deze informatie op één locatie kunt wijzigen en deze wijzigingen zullen automatisch worden weerspiegeld op alle pagina's.
Store and retrieve Application variables
Application variables can be accessed and modified 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 sure 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 %>
Locking and unlocking
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