Name

Session_OnEnd — Session_OnEnd

Synopsis

Triggered when the user's session times out or when your scripts call the Abandon method of the Session object.

The OnEnd event procedure, if it exists, resides in the GLOBAL.ASA file for the application that contains the requested page.

Parameters

None

Example

<SCRIPT LANGUAGE = "VBScript" RUNAT = Server>

Sub Session_OnEnd

   ' If the user has a search results recordset open, close
   ' it:
   If IsObject(adoRSResults) Then
      Set adoRSResults = Nothing
   End If

End Sub

</SCRIPT>

Notes

In the code for the OnEnd event procedure, you have access only to the Application, Server, and Session objects. Most important, you have no access to the Response object or Request object, and, for this reason, you cannot redirect the client or send cookies to (or receive cookies from) the client machine.

One of the possible uses of the OnEnd event is to write information concerning the user to a log file or other text file on the server for later use. If you intend to do this, there are several important points you must remember. First, before you can save any information, that information must be saved to a session variable because, as mentioned earlier, you do not have access to the Request object, which is the most common source of user information. The following code demonstrates one possible method of storing a session-level variable:

<SCRIPT LANGUAGE = "VBScript" RUNAT = Server> Sub Session_OnEnd ' Assume that SessionVar1 contains some user-preference ' information. ...

Get ASP in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.