the application object represents a collection of asp pages. the application object has zero (0) properties, two (2) collections, two (2) methods, and two (2) events.
below are a couple scripts for lesson11.
click here to run script11.asp in a new window. below is script11a.asp.
the two collections are contents and staticobjects. staticobjects come in the form of the <object> flag. that's done in the global.asa that we saw in lesson 09. i'll demonstrate it again down below.
by contrast, the contents collection is demonstrated above. it allows you to set and retrieve variables with application scope. the format for setting an application variable is application.contents("variablename")="variablevalue". however, since contents is the default collection, we have a little shortcut for setting application variables. the shortcut goes like this: application("variablename")="variablevalue".
share the variable:
one last thought on application variables. the application variable is shared by all visitors. let's say that you and i are on the same asp web site at the same time. if you set the background color to white in script11.asp, then i will see "white" as the official color if i go directly to script11a.asp. application variables are by no means the most efficient means of passing information from one user to another.
no apartment model:
you may notice that the example above seems to be inefficient. why not just directly assign application("officialcolor") = request.form("officialcolor")? because we can't. by design, the newer (and updated) versions of microsoft server software intentionally do not support apartment model behavior.
the two application methods are lock() and unlock(). lock() blocks all other users from changing the application variables. unlock() releases control so that other users can change it. that's important on a larger site where multiple users may be trying to access the same page at the same time.
the two application events are application_onstart() and application_onend(). these events are accessed in the global.asa. let's repeat that script from lesson 09.
application.contents has two methods of its own. application.contents.remove("variablename") and application.contents.removeall().
you'll notice there are also session events in the global.asa. we'll deal with those in lesson 12. you'll also notice a call to the ado library. we'll talk about that when we get to databases.