
Item | 409
SessionState
Class
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
IsReadOnly
Boolean = Session.IsReadOnly
Returns a Boolean indicating whether the current session can be written to from
the current page. This property is set to
True when the EnableSessionState
attribute of the @ Page directive is set to ReadOnly.
Parameter
Boolean
A Boolean variable that will receive the IsReadOnly property value. The
default is
False.
Example
The example tests whether the session is set to ReadOnly for the page and if so,
displays an appropriate message. If not, it writes a value to the Session collection
and then displays a different message:
Sub Page_Load( )
If Session.IsReadOnly Then
Message.Text = "The current Session (SessionID: " & _
Session.SessionID & ") is read-only for this page."
Else
Session("foo") = "foo"
Message.Text = "The current Session (SessionID: " & _
Session.SessionID & ") can be written to from this page."
End If
End Sub
To test this page, add the EnableSessionState attribute to the @ Page directive for
the page, setting its value to
ReadOnly, as shown here:
<%@ Page Language="vb" EnableSessionState="ReadOnly" %>
Notes
Read-only session state is new in ASP.NET and is designed to improve the effi-
ciency of pages that require only read access to the Session collection. Attempting
to write to the Session collection from a page ...