SessionStateItemCollection.Deserialize(BinaryReader) 方法

定义

使用 SessionStateItemCollection 方法在要写入的存储位置创建一个 Serialize(BinaryWriter) 集合。Creates a SessionStateItemCollection collection from a storage location that is written to using the Serialize(BinaryWriter) method.

public:
 static System::Web::SessionState::SessionStateItemCollection ^ Deserialize(System::IO::BinaryReader ^ reader);
public static System.Web.SessionState.SessionStateItemCollection Deserialize (System.IO.BinaryReader reader);
static member Deserialize : System.IO.BinaryReader -> System.Web.SessionState.SessionStateItemCollection
Public Shared Function Deserialize (reader As BinaryReader) As SessionStateItemCollection

参数

reader
BinaryReader

用于从流或编码的字符串读取序列化的集合的 BinaryReaderThe BinaryReader used to read the serialized collection from a stream or encoded string.

返回

SessionStateItemCollection

一个 SessionStateItemCollection 集合,使用 Serialize(BinaryWriter) 方法向该集合填充了存储位置写入的内容。A SessionStateItemCollection collection populated with the contents from a storage location that is written to using the Serialize(BinaryWriter) method.

例外

会话状态信息无效或损坏The session state information is invalid or corrupted

示例

下面的代码示例 SessionStateItemCollection 使用方法创建一个从文件创建的集合 SerializeThe following code example creates a SessionStateItemCollection collection from a file that was created using the Serialize method.

System.IO.BinaryReader reader = new System.IO.BinaryReader(
  System.IO.File.Open(Server.MapPath("session_collection.bin"), System.IO.FileMode.Open));

SessionStateItemCollection sessionItems = SessionStateItemCollection.Deserialize(reader);

for (int i = 0; i < sessionItems.Count; i++)
  Response.Write("sessionItems[" + i + "] = " + sessionItems[i].ToString() + "<br />");
Dim reader As System.IO.BinaryReader = New System.IO.BinaryReader( _
  System.IO.File.Open(Server.MapPath("session_collection.bin"), System.IO.FileMode.Open))

Dim sessionItems As SessionStateItemCollection = SessionStateItemCollection.Deserialize(reader)

For I As Integer = 0 To sessionItems.Count - 1
  Response.Write("sessionItems(" & i & ") = " & sessionItems(i).ToString() & "<br />")
Next

注解

重要

使用不受信任的数据调用此方法存在安全风险。Calling this method with untrusted data is a security risk. 仅使用受信任的数据调用此方法。Call this method only with trusted data. 有关详细信息,请参阅数据验证For more information, see Data Validation.

Deserialize方法可用于 SessionStateItemCollection 从会话存储区中读取集合的内容。The Deserialize method can be used to read the contents of a SessionStateItemCollection collection from the session store.

若要将对象的内容写入 SessionStateItemCollection 会话存储,请使用 Serialize 方法。To write the contents of a SessionStateItemCollection object to the session store, use the Serialize method.

适用于