119电脑网

当前位置: 主页 > Asp >

session变量可以申请数组吗?

时间:2013-09-19 18:29来源: 作者: 点击:
you store an array in a session object, you should not attempt to alter the elements of the stored array directly. For example, the following script will not work。

  If you store an array in a Session object, you should not attempt to alter the elements of the stored array directly. For example, the following script will not work:<br>
<br>
&lt;% Session(&quot;StoredArray&quot;)(3) = &quot;new value&quot; %&gt;<br>
<br>
This is because the Session object is implemented as a collection. The array element StoredArray(3) does not receive the new value. Instead, the value is indexed into the collection, overwriting any information stored at that location. <br>
<br>
It is strongly recommended that if you store an array in the Session object, you retrieve a copy of the array before retrieving or changing any of the elements of the array. When you are done with the array, you should store the array in the Session object again so that any changes you made are saved. This is demonstrated in the following example:<br>
<br>
---file1.ASP---<br>
&lt;%<br>
'Creating and initializing the array<br>
Dim MyArray()<br>
Redim MyArray(5)<br>
MyArray(0) = &quot;hello&quot;<br>
MyArray(1) = &quot;some other string&quot;<br>
<br>
'Storing the array in the Session object.<br>
Session(&quot;StoredArray&quot;) = MyArray<br>
<br>
Response.Redirect(&quot;file2.ASP&quot;)<br>
%&gt;<br>
<br>
---file2.ASP---<br>
&lt;%<br>
'Retrieving the array from the Session Object<br>
'and modifying its second element.<br>
LocalArray = Session(&quot;StoredArray&quot;)<br>
LocalArray(1) = &quot; there&quot;<br>
<br>
'Printing out the string &quot;hello there.&quot;<br>
Response.Write(LocalArray(0)&LocalArray(1))<br>
<br>
'Re-storing the array in the Session object.<br>
'This overwrites the values in StoredArray with the new values.<br>
Session(&quot;StoredArray&quot;) = LocalArray<br>
%&gt;<br>
<br>

回顾文章:ASP.NET Session详解

懂得ASP/ASP.NET编程 了解ASP/ASP.NET的session模型 了解ASP.NET Web应用程序模型 了解ASP.NET Web应用程序配置文件Web.config的作用、意义及使用方法 了解Internet Information Services(以下简称IIS)的基本使用方法 了解如何在Microsoft SQL Server中创建一个数据库。

(责任编辑:admin)
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片
推荐内容
  • Session 详解

    懂得ASP/ASP.NET编程 了解ASP/ASP.NET的session模型 了解ASP.NET Web应用程序模型 了...

  • SessionID

    SessionID 属性返回用户的会话标识。在创建会话时,服务器会为每一个会话生成一个单独...

  • sp+语法介绍(六)----数据库篇

    在下面的例子中,我们将要介绍一下lt;ASP:datagrid runat=servergt;控件是怎么样通过s...

  • 保护你ASP页面的两种办法

    保护你的ASP页面的两种办法。保护你的asp页面并不难,我们可以用Request.ServerVariab...

  • Sucess On a Horse

    Enoloo and I disussed the How to earn Money.Actually,he didn...

  • VB/ASP数据库连接字符串示例

    使用DSN的数据库连接字符串例:MS SQL / MySQL / PostgreSQLDSN=dsnname 不使用DSN数据...