Programming Microsoft ASP.NET 4 - Dino Esposito [352]
Figure 17-2. Page access to the session state is synchronized, and a serialization/deserialization layer ensures that each request is served an up-to-date dictionary of values, stored at the application’s convenience.
Note
Concurrent access to the session state is not very common in reality. It might happen if you have a multiframe page or if your users work with two copies of the same page or multiple pages of the same application at the same time. It also happens when you use session-enabled HTTP handlers to serve embedded resources such as images or cascading style sheet (CSS) files. By default, you are protected against concurrent accesses. However, declaring the exact use of the session state that a page is going to make (read/write, readonly, or no use) is an excellent form of optimization. You do this through the EnableSessionState attribute on the @Page directive.
Properties of the HttpSessionState Class
The HttpSessionState class is defined in the System.Web.SessionState namespace. It is a generic collection class and implements the ICollection interface. The properties of the HttpSessionState class are listed in Table 17-5.
Table 17-5. HttpSessionState Properties
Property
Description
CodePage
Gets or sets the code page identifier for the current session.
Contents
Returns a reference to this object. It’s provided for ASP compatibility.
CookieMode
Details the application’s configuration for cookieless sessions. Declared to be of type HttpCookieMode. (I’ll discuss this in more detail later.)
Count
Gets the number of items currently stored in the session state.
IsCookieless
Indicates whether the session ID is embedded in the URL or stored in an HTTP cookie. It’s more specific than CookieMode.
IsNewSession
Indicates whether the session was created with the current request.
IsReadOnly
Indicates whether the session is read-only. The session is read-only if the EnableSessionState attribute on the @Page directive is set to the keyword ReadOnly.
IsSynchronized
Returns false. (See references to this later in the chapter.)
Item
Indexer property, provides read/write access to a session-state value. The value can be specified either by name or index.
Keys
Gets a collection of the keys of all values stored in the session.
LCID
Gets or sets the locale identifier (LCID) of the current session.
Mode
Gets a value denoting the state client manager being used. Acceptable values are listed in Table 17-4.
SessionID
Gets a string with the ID used to identify the session.
StaticObjects
Gets a collection including all instances of all objects declared in global.asax using an