Use the Contents collection to save session information
1. The Contents collection is a set of variables defined in an ASP application using the Session object. These variables are scoped to the user layer and are available throughout the ASP application. This is the default collection of Session objects, so the following two formats are equivalent:
Session.Contents("变量名")
Session("变量名")
where "variable name" is the name of the session variable that needs to be manipulated.
2. Instance code (1.asp): Write a simple counter program using the Session object.
<body>
<center>
<p>使用 Session 变量<p>
</center>
<%
Session.Contents("counter")=Session.Contents("counter")+1
%>
<center>
<font size=6 face=方正舒体 color=blue>
您是第<%=Session.Contents("counter")%>次来访!
</font>
</center>
</body>
Ii. using the StaticObjects collection to save session information
The StaticObjects collection contains all objects created with object tags in the Session object.
1, StaticObjects set of syntax format:
Session.StaticObjects (key) where the parameter key specifies the property to retrieve. 2. Create an object with session scope:
In the Global.asa file, you can create an object with a session scope by using the OBJECT tag and setting the SCOPE property to sessions. For example:
<OBJECT RUNAT=”Server" SCOPE="Session" ID=名称 PROGID=类名></OBJECT> 3. Use for Each ... Next statement to traverse each object in the StaticObjects collection
The StaticObjects collection can be used to determine the value of an object-specific property, or to traverse a collection and get all the properties of all objects. Use the loop control structure to traverse the keywords in the StaticObjects collection. The script is as follows:
<%
For Each objprop in Session.StaticObjects
Response.Write objprop & ":" & Session.StaticObjects(objprop) & "<br>"
Next
%> 4. You cannot store built-in objects in the Session object. For example, each of the following lines of script will return an error.
<%
set session("varl")=Session
set session("var2")=Request
set Session("var3")=Response
set Session("var4")=Server
set Session("var5")Application
%>