Reading Form Data

The Application Object

You can use the Application object to share information among all users of a Web application.

A Web application starts when the first user of your application requests an .asp file from the virtual root of your Web application. The application ends when the Web server is shut down.

You can create and store values in the Application object in the same way that you store values in the Session object. The difference is that the information stored in the Application object is available from the time the first user makes an HTTP request for an ASP until the Web server shuts down.

For example, if you want to display information to all users of your Web application, you can create an administrative page that enables a specified person to enter information for all users. This page writes the information to the Application object, so you can use the information on other Active Server Pages. In this way, each user receives the same administrative information from one place.

Syntax

Use the following syntax to set the methods of the Application object:
 Application.  method  

Example

This example shows how you might add information collected from an administrative page to a Web application:
 <% Application("TodaysLecture") = Request.Form("lecture") Application("location") = Request.Form("location") 

Example

This example shows how to use the information specified in the preceding example code:
 Don't miss today's lecture in room <%= Application("location") %>, titled <%= Application("TodaysLecture") %> 

Locking and Unlocking the Application Object

All users share the same Application object, so it is possible that two users might attempt to modify the object simultaneously . The Lock and Unlock methods of the Application object prevent this possibility. The Application object needs to be locked only while it is being modified.

To reduce the inconvenience to a user of not being able to access the Application object when it is necessary, try to keep the amount of time you use the Lock method to a minimum.

Example

This example shows how to use the Lock and Unlock methods when changing the value of a hit counter used in a Web application:
 <% Application.Lock Application("NumVisits") = Application("NumVisits") + 1 Application.Unlock %> This application has been visited  <%= Application("NumVisits") %> times. 


Microsoft Windows Architecture Training
Microsoft Windows Architecture for Developers Training Kit
ISBN: B00007FY9D
EAN: N/A
Year: 1998
Pages: 324

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net