
632
|
Chapter 35: The System.Web.SessionState Namespace
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
HttpSessionState
System.Web.SessionState (system.web.dll)
sealed class
The HttpSessionState class provides server-side state management that is stored on a per-
client basis. The HttpSessionState class exposes a key/value collection of items that can
store simple value types or instances of any serializable .NET class. You can also store
instances of your own custom objects in session state, provided you make them serial-
izable by adding the SerializableAttribute to the class declaration. You can add and access
items in the HttpSessionState collection as you would with other ASP.NET collections,
including System.Web.HttpApplicationState and System.Web.Caching.Cache. Unlike these classes,
session state can be stored outside of the main ASP.NET process. This allows it to be
shared across multiple computers in a web farm and persist after server restarts.
The HttpSessionState class combines two state collections: Contents and StaticObjects. The Static-
Objects collection contains the application state objects that are defined in the global.asax
file with <object runat="server"> tags. This collection is immutable. The Contents collection
contains all the state objects added at runtime.
The Item collection is the default indexer for