Please visit our sponsors !
ASP Application Object
A group of ASP files that work together to perform some purpose
is called an application.
The Application object in ASP is used to tie these files together.
Application Object
An application on the Web is a group of ASP files. The files work together to perform some purpose.
The Application object in ASP is used to tie these files together.
The Application object is used to store variables
and access variables from any page, just like the Session object. The difference
is that all users share ONE Application object, while with Sessions there
is one Session object for each user.
The Application object should hold information that will be used by many
pages
in the application (like database connection information). This means that you
can access the information from any page. It also means that you can change the
information in one place and the new information will automatically be reflected
on all pages.
Store and Retrieve Variable Values
Application variables can be accessed and changed by any page in the application.
You can create Application variables in Global.asa like this:
<script language="vbscript" runat="server">
Sub Application_OnStart
application("vartime")=""
application("whoon")=1
End Sub
</script>
|
In the example above we have created two Application variables: The first is
named vartime, and the second is named whoon.
You can access the value of an Application variable like this:
There are
<%
Response.Write(Application("whoon"))
%>
active connections.
|
Looping Through the Contents
You can loop through the "Contents" collection, to see the values
of all the Application variables:
<%
dim i
For Each i in Application.Contents
Response.Write(i & "<br>")
Next
%>
|
If you don't know how many items are stored in a "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
%>
|
Looping Through the Objects
You can loop through the "StaticObjects" collection, to see the
values of all the objects stored in the
Application Object:
<%
dim i
For Each i in Application.StaticObjects
Response.Write(i & "<br>")
Next
%>
|
Lock and Unlock
You can lock an application with the "Lock" method. When an
application is locked, the users cannot change the Application variables (other than the one currently accessing
it). You can unlock an application with the "Unlock" method. This method
removes the lock from the Application variable:
<%
Application.Lock
'do some application object operations
Application.Unlock
%>
|
Jump to: Top of Page
or HOME or
Printer friendly page
Search W3Schools:
What Others Say About Us
Does the world know about us? Check out these places:
Dogpile
Alta Vista
MSN
Google
Excite
Lycos
Yahoo
Ask Jeeves
We Help You For Free. You Can Help Us!
W3Schools is for training only. We do not warrant its correctness or its fitness for use.
The risk of using it remains entirely with the user. While using this site, you agree to have read and accepted our
terms of use and
privacy policy.
Copyright 1999-2002 by Refsnes Data. All Rights Reserved
|