当前位置:早雪网网络学院编程文档ASP → Developing ASP-Based Applications

Developing ASP-Based Applications

减小字体 增大字体 作者:佚名  来源:本站整理  发布时间:2005-6-23 16:24:51

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>

Application-End and Session-End Events
The application-end and session-end events are Application_OnEnd and Session_OnEnd, respectively. Like the application-start and session-start events, these events are procedures that you include in a Global.asa file. Unlike start events, end events occur only when a session or application ends; thus, you should include in them any scripts that you want to run at those times. If a session and an application end at the same time, ASP processes the session-end event before it processes the application-end event.

Use the following syntax to define a session-end event:

<script LANGUAGE=VBscript RUNAT=Server>
Sub Session_OnEnd
  ' This is where you would insert script for a session-end event.
End Sub
</script>

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

<script LANGUAGE=VBscript RUNAT=Server>
Sub Application_OnEnd
   'This is where you insert script for an application ending event.
End Sub
</script>

Ending a Session
A session automatically ends if a user has not requested or refreshed a page in an application for a specified period of time. This value is 20 minutes by default. (Refer to Configuring Registry Entries for information about changing the default value).

You can explicitly end a session with the Abandon method of the Session object. For example, you can provide a Quit button on a form with the ACTION parameter set to the URL of an .asp file that contains the following command.

<% Session.Abandon %>

If, for a specific session, you want to set a timeout interval that is longer than the 20-minute default, you can set the Timeout property of the Session object. For example, the following scr

[1] [2] [3]  下一页

[数据载入中...] [返回上一页] [打 印]