You can use the Session object to store information needed for a particular user-session. Variables stored in the Session object are not discarded when the user jumps between pages in the application; instead, these variables persist for the entire user-session.
The Web server automatically creates a Session object when a Web page from the application is requested by a user who does not already have a session. The server destroys the Session object when the session expires or is abandoned.
One common use for the Session object is to store user preferences set on a previous visit to the Web application, such as high, medium, or low graphics.
Note Session state is only maintained for browsers that support cookies.
Syntax
Session.property|method
Properties
Returns the session identification for this user. | |
The timeout period for the session state for this application, in minutes. |
Methods
This method destroys a Session object and releases its resources. |
Remarks
You can store values in the Session object by using the following syntax:
<% Session("username") = "Janine" Session("age") = 24 %>
However, if you store an object in the Session object using VBScript as your primary scripting language you must use the following syntax. (note the use of the Set keyword in the second line.)
<% Set MyObj = Server.CreateObject("MyComponent") Set Session("Obj1") = MyObj %>
You can then call the methods and properties of MyObj on subsequent Web pages, by using the following:
<% Session("Obj1").MyObjMethod %>
Note You can also create objects with session scope by using the <OBJECT> tag in the Global file. For more information, see the Global File Reference.
You cannot store a built-in object in a Session object. For example, each of the following lines would return an error.
<% Set Session("var1") = Session Set Session("var2") = Request Set Session("var3") = Response Set Session("var4") = Server Set Session("var5") = Application %>
Examples
<% Session("name") = "MyName" Session("year") = 96 Set Session("myObj") = Server.CreateObject("someObj") %>
Events
Scripts for the following events are declared in the Global file.
For more information about these events and the Global file, see the Global File Reference.