|
Communication between a browser and a Web server uses the HTTP protocol. This protocol is stateless, meaning that there is no information retained when a user goes from one page to another. In a real-world application, it is usually necessary to retain information between pages visited by the same user. The use of an application by a single user is called a session.
Sun Chili!Soft ASP includes the built-in Session object for retaining session information. When a new session starts, an instance of the Session object is created automatically. You can assign variables and object instances to session variables so that they are available to all pages of the application visited by the same user.
The global.asa file can contain the following handlers for two session-level events: Session_OnStart and Session_OnEnd, which are described later in this topic. These subroutines are automatically executed the first time a user accesses an ASP page within the application. Sessions exist until one of the following occurs:
· The user closes the browser
· The session times out (configurable by the ASP developer)
· The session is explicitly abandoned (Session.Abandon)
The ENABLESESSIONSTATE @ directive turns off session tracking for a page. If your page does not rely on session information, turning off session tracking can decrease the time it takes Sun Chili!Soft ASP to process the script. By default, sessions are enabled.
<%@ ENABLESESSIONSSTATE=True|False %>
The Session_OnStart event occurs when the server creates a new session. The server processes this script prior to executing the requested page. The Session_OnStart event is where, when you set any session-wide variables, those variables will be set before any pages are accessed. All of the built-in objects are available and can be referenced in the Session_OnStart event script.
<SCRIPT LANGUAGE=ScriptLanguage RUNAT=Server>
Sub Session_OnStart
. . .
End Sub
</SCRIPT>
ScriptLanguage
Specifies the scripting language used to write the event script, either VBScript or JScript. If more than one event uses the same scripting language, the events can be enclosed within a single set of <SCRIPT> tags.
Runat
Must be "Server."
The Session_OnEnd event occurs when a session is abandoned or times out. Only the Application, Server and Session built-in objects are available.
<SCRIPT LANGUAGE=ScriptLanguage RUNAT=Server>
Sub Session_OnEnd
. . .
End Sub
</SCRIPT>
ScriptLanguage
Specifies the scripting language used to write the event script, either VBScript or JScript. If more than one event uses the same scripting language, the events can be enclosed within a single set of <SCRIPT> tags.
Runat
Must be "Server."
See also:
Specifying Application Events in this chapter
Using the global.asa File in this chapter
Saving Changes to the global.asa File in this chapter
Copyright 2002 Sun Microsystems, Inc. All rights reserved. Legal Notice.