This section provides a tutorial example on how to use the 'session' object provided by the ASP programming interface to share data across ASP pages.
session: An object provided by the server to hold information and methods
common to all ASP pages running under one session.
Contents: A collection object acting an cache for different ASP pages to
share information. Since "Contents" is the default collection, we write
'session.Contents("myVar")' as 'session("myVar")'.
Abandon(): A method to destroy the current session.
SessionID: A read only property to return the id of the current session.
TimeOut: A property to set timeout period on this session.
OnStart(): An event handler to be called when the first HTTP request comes
from a new user.
OnEnd(): An event handler to be called the session is abandoned or timed out.
Here is a simple ASP page shows you the session object, session_test.asp:
<script language="vbscript" runat="server">
' session_test.asp
' Copyright (c) 2002 by Dr. Herong Yang
session("PATH_INFO") = request.ServerVariables("PATH_INFO")
response.write("<html><body>")
response.write("<b>Tests on the session object</b>:<br/>")
response.write("session.SessionID = " & session.SessionID & "<br/>")
set c = session.Contents
response.write("session.Contents.Count = " & c.Count & "<br/>")
for each v in c
response.write( v & " = " & c.Item(v) & "<br/>")
next
response.write("</body></html>")
</script>
Output:
Tests on the session object:
session.SessionID = 1018427069
session.Contents.Count = 1
PATH_INFO = /session_test.asp
Note that session.Contents is empty initially. I added the "PATH_INFO" of the current request to
it to show you how add and retrieve a parameter from session.Contents.