5.2.4 Session Events

Communication between a browser and a web server uses the HTTP protocol for communication. This protocol is stateless, meaning that there is no memory between successive pages. In a real-world application, it is usually necessary to information between pages used by the same client. The use of an application by a single user is called a Session, and ASP has a built-in object (the Session object) for dealing with session information. An instance of the Session object is created automatically when a new session starts. Variables and object instances can be assigned to session variables so that they are available to all pages of the application run by the same user.
The Global.asa file can contain handlers for two Session level events: Session_OnStart and Session_OnEnd. These subroutines are automatically executed the first time a user access an ASP page within the application. Sessions exist until:
- the user closes the browser
- the session times out (configurable by the programmer)
- the session is explicitly abandoned (Session.Abandon)
An instance of the Session Object is created automatically when a new session starts. Variables and object instances can be assigned to session variables so that they are available to all pages of the application run by the same user
5.2.4.1 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 you set any session-wide variables, they will be set before any pages are accessed. All the built-in are available and can be referenced in the Session_OnStart event script.
Syntax
<SCRIPT LANGUAGE=ScriptLanguage RUNAT=Server>
Sub Session_OnStart
. . .
End Sub
</SCRIPT>
Parameters
- ScriptLanguage
- Specifies the scripting language used to write the event script. It may be any supported scripting language, such as VBScript or JScript. If more than one event uses the same scripting language, they can be combined under a single set of <SCRIPT> tags.
- Runat
- Must be "Server".
5.2.4.2 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
<SCRIPT LANGUAGE=ScriptLanguage RUNAT=Server>
Sub Session_OnEnd
. . .
End Sub
</SCRIPT>
Parameters
- ScriptLanguage
- Specifies the scripting language used to write the event script. It may be any supported scripting language, such as VBScript or JScript. If more than one event uses the same scripting language, they can be combined under a single set of <SCRIPT> tags.
- Runat
- Must be "Server".
Copyright © 2000 Chili!Soft
|