Redigera

Dela via


SessionStateItemCollection.Deserialize(BinaryReader) Method

Definition

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

Parameters

reader
BinaryReader

The BinaryReader used to read the serialized collection from a stream or encoded string.

Returns

A SessionStateItemCollection collection populated with the contents from a storage location that is written to using the Serialize(BinaryWriter) method.

Exceptions

The session state information is invalid or corrupted

Examples

The 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

Remarks

Important

Calling this method with untrusted data is a security risk. Call this method only with trusted data. For more information, see Validate All Inputs.

The Deserialize method can be used to read the contents of a SessionStateItemCollection collection from the session store.

To write the contents of a SessionStateItemCollection object to the session store, use the Serialize method.

Applies to

See also