Home

ASP ADVANCED

In this chapter, you learn how to work with applications.  The first section provides an overview of applications.  In the second section, you learn how to use the methods, collections, and events of applications.  Finally, in the third section, two programming examples using applications are discussed.  You learn how to create a simple multiuser chat program.  You also learn how to create an Active Server Page that displays real-time usage statistics for your Web site.

Microsoft wants you to think of Active Server Pages in traditional programming terms.  When you create a single Active Server Page, you're creating something like a procedure or subroutine.  When you create a group of related Active Server Pages, you're creating an application.

However, an application is something more than a group of pages sitting on a hard drive.  When Active Server Pages are joined together in an application, they have certain properties that they would otherwise lack.  Following is a list of some features of an Active Server Pages application:

  • Data can be shared among the pages in an application, and therefore among more than one user of a Web site.
  • An application has events that can trigger special application scripts.
  • An instance of an object can be shared among all the pages in an application.
  • Separate applications can be configured with the Internet Service Manager to have different properties.
  • Separate applications can be isolated to execute in their own memory space.  This means that if one application crashes, the others won't also crash.
  • You can stop one application (unloading all of its components from memory) without affecting other applications.

A Web site can have more than one application.  Typically, you create separate applications when you have collections of pages related to separate tasks.  For example, you might create one application containing all the pages meant for public consumption. You might create another application that's restricted to use by Web site administrators.

You can also create separate applications that correspond to distinct Web sites hosted on the same computer.  For example, the same computer might host an application for Tom's Online Flower Shop and an application for Roger's Web Book Shop.

An application is defined by using the Internet Service Manager to specify a root directory for the application.  An application consists of a particular directory and all of its subdirectories.  If one of these subdirectories is also defined to be an application, then it constitutes a separate application.  In other words, no two applications overlap.

When you first install Active Server Pages, a few applications are created by default.  For example, an application is created for your default Web site.  However, you can create as many additional applications as you need.

Follow these steps to define an Active Server Pages application:

  1. Launch the Internet Service Manager from the Microsoft Internet Information Server program group.
  2. Click the name of your default Web site in the navigation tree. (If you haven't changed anything, it will be named Default Web Site.)
  3. You can select any existing directory, the default Web site, or create a new directory for your application.  To create a new virtual directory, right-click the name of your default Web site and then choose New I Virtual Directory.
  4. After you have chosen a directory for your application, you need to view its property sheet.  You can do this by clicking the Properties icon or by right-clicking the name of the directory and choosing Properties.
  5. In the property sheet, click the tab labeled either Virtual Directory or Home Directory.
  6. In the Application Settings section, click the Create button.

You have now successfully created a new application.  After you create an application, you can set a number of its properties by selecting Configuration from the Application Settings panel.  For example, you can specify whether the application should use sessions or whether the application should buffer Active Server Pages.

Furthermore, once you create an application, you can provide it with its own Global.asa file that contains application-wide scripts.  You place this file in the root directory of the application.  You learn more about using this file in the later section "Application Events."