Sun Chili!Soft ASP Sun Chili!Soft
ASP Sun Microsystems

 

Managing User Sessions

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)

Turning Session Tracking On and Off

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.

Syntax

<%@ ENABLESESSIONSSTATE=True|False %>

ASP Session_OnStart Event

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.

Syntax: Session_OnStart Event

<SCRIPT LANGUAGE=ScriptLanguage RUNAT=Server>

Sub Session_OnStart

. . .

End Sub

</SCRIPT>

Parameters: Session_OnStart Event

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."

ASP Session_OnEnd Event

The Session_OnEnd event occurs when a session is abandoned or times out. Only the Application, Server and Session built-in objects are available.

Syntax: ASP Session_OnEnd Event

<SCRIPT LANGUAGE=ScriptLanguage RUNAT=Server>

Sub Session_OnEnd

. . .

End Sub

</SCRIPT>

Parameters: ASP Session_OnEnd Event

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.