HOME

ASP Tutorial
ASP HOME
ASP Introduction
ASP Install
ASP Syntax
ASP Variables
ASP Procedures
ASP Forms
ASP Cookies
ASP Session
ASP Application
ASP #include
ASP Global.asa

ASP Objects
ASP Response
ASP Request
ASP Application
ASP Session
ASP Server
ASP Error

ASP FileSystem
ASP TextStream
ASP Drive
ASP File
ASP Folder
ASP Dictionary

ASP Components
ASP AdRotator
ASP BrowserCap
ASP Content Linking
ASP Content Rotator

ASP Quick Ref

Examples/Quiz
ASP Examples
ASP Quiz Test

ADO
ADO Introduction

Resources
ASP Resources

Please visit our sponsors !

ASP Application Object

previous next

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
%>


previous next

Jump to: Top of Page or HOME or Printer Friendly 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


Validate How we converted to XHTML Validate

IISProtect
Password Protect
Your Web Pages



Your own Web Site?

Read W3Schools
Hosting Tutorial



$15 Domain Name
Registration
Save $20 / year!



Advertise
at W3Schools

Only 0.5 CPM



SELECTED LINKS

University Online
Master Degree
Bachelor Degree


Web Software

The Future of
Web Development


Jobs and Careers

Web Security
Web Statistics
Web Standards


PARTNERS

W3Schools
TopXML
VisualBuilder
XMLPitstop
DevelopersDex
DevGuru
Programmers Heaven
The Code Project
Tek Tips Forum
ZVON.ORG
TopXML Search