Open Directory Site ASP Tutorials

ASP | XML | VBScript | JavaScript | ADO | CSS | XMLDOM | PHP | Operating Systems

Home >> ASP >>ASP Applications

 ASP Applications

 

Applications

The Application Object is used to tie together Web pages into an application. The Application Object store variables and objects for the entire application. Any page that is a part of this application can access these variables and objects. There is one instance of the Application Object for each application running on the server, but many clients can access the same application.

Store and Retrieve Variables Values

Application variables and objects must be declared in the Global.asa file, but they can be accessed and changed by any page in the application.

You can store variables in the Application Object (in global.asa), like this:

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

Sub Application_OnStart

application("vartime")=""

application("whoon")=1

End Sub

</script>

You can get variable values from the Application Object, 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 variables stored in the Application Object:

<%

dim i

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

Next

%>

Result:

1

If you do not know how many items that 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

%>

Result:

1

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(Application.StaticObjects(i) & "<br>")

Next

%>

Lock and Unlock

You can lock an application with the "Lock" method. This method prevents users (other than the one currently accessing it), from changing the Application variables:

<%

Application.Lock

%>

You can unlock an application with the "Unlock" method. This method removes the lock from the Application variable:

<%

Application.Unlock

%>

Cheap Web Hosting Articles - Web Site Design & Web Hosting Tutorials - Domain Hosting