ASP Getting Started Tutorial-saving session information

Source: Internet
Author: User

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
    %>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.