日期:2008-11-04  浏览次数:20911 次


An ASP-based application consists of a virtual directory on a Web server and all the folders and files within that virtual directory. For more information about virtual directories, refer to your Microsoft Web server online documentation.

An application can be a simple home page; it can include a number of dynamic elements, such as the custom home page of the MSN™ online service (www.msn.com); or it can consist of a complex set of interrelated pages and logic.

When you use ASP-based applications, you are able to maintain state. State is the ability to retain information. You can use ASP to maintain two types of state:

Application state, in which all information pertaining to an application is available to all users of an application.
Session state, in which information is available only to a user of a specific session.
The ASP tools you use to manage state are the Session and Application built-in objects.

Using the Session and Application Objects
You can use the ASP built-in objects Session and Application to extend the functionality of your ASP-based applications.

Use the Session object to manage information for a user when that user is using an application. A session belongs, in effect, to a single user. The Application object is used to store common information that can be shared between all users of a single ASP-based application.

Using the Global.asa File
Each ASP-based application can have one Global.asa file. (The file name extension .asa stands for “Active Server Application.”) This file must be stored in the root directory of the application. ASP reads a Global.asa file when:

The Web server receives the first post-startup request for any .asp file in a given application; that is, after the Web server starts, the first request for any .asp file in an application causes ASP to read the Global.asa file for that application.
A user who does not have a session requests an .asp file in an application.

You can include the following in a Global.asa file:

Application-start events, session-start events, or both.
Application-end events, session-end events, or both.
Object tags. You can use the <OBJECT> tag to create objects in a Global.asa file. Refer to Setting Component Scope for information about creating objects with this tag.

Refer to Global.asa Reference for more information.

Application-Start and Session-Start Events
The application-start and session-start events are Application_OnStart and Session_OnStart, respectively. You should include in these procedures scripts that you want to run whenever an application or session starts. If an application and a session start at the same time, ASP processes the application-start event before it processes the session-start event.

Use the following syntax to define an application-start event:

<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Application_OnStart
' This is where you would insert script for an application-start event.
End Sub
</SCRIPT>

To create an instance of the Ad Rotator component whenever a session starts, you could define the following procedure:

<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Session_OnStart
Set Session("MyAd")=Server.CreateObject("MSWC.Adrotator")
End Sub
</SCRIPT>

Applicatio