"session" Object - Sharing Data across ASP Pages

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.

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("<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/>")


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.

Last update: 2002.

Table of Contents

 About This Book

 ASP (Active Server Pages) Introduction

 IIS (Internet Information Services) 5.0

 MS Script Debugger

 VBScript Language

ASP Built-in Run-time Objects

 Introduction of ASP Objects

 "request" Object - Receiving Data from Client

 "response" Object - Sending Data to Client

 "server" Object - Sharing Data across Applications

 "application" Object - Sharing Data within an Application

"session" Object - Sharing Data across ASP Pages

 ASP Session

 Creating and Managing Cookies

 Managing Sessions with and without Cookies

 scrrun.dll - Scripting Runtime DLL

 Managing Response Header Lines

 Calculation Speed and Response Time

 ADO (ActiveX Data Object) DLL

 Working with MS Access Database

 Guest Book Application Example


 PDF Printing Version