ASP.NET Session State
Thursday, July 7, 2011 3:00:18 PM
Note The code in this article is targeted for the beta version of Microsoft .NET. Some of the code may require reworking in order to function correctly on later versions of the .NET Framework.
In this month's column we're going to pick up the pace a bit and dive straight into some of the new features of ASP.NET. We'll start by comparing ASP.NET session state with classic ASP, then show code and examples for how you can configure and use ASP.NET session state.
A session is defined as the period of time that a unique user interacts with a Web application. Active Server Pages (ASP) developers who wish to retain data for unique user sessions can use an intrinsic feature known as session state.
Programmatically, session state is nothing more than memory in the shape of a dictionary or hash table, e.g. key-value pairs, which can be set and read for the duration of a user's session. For example, a user selects stocks to track and the Web application can store these values in the user's ASP session instance:
Session("Stocks") = "MSFT; VRSN; GE"
On subsequent pages these values are read and the Web application has access to these values without the user re-entering them:
' Get Stocks, split string, etc.
Dim StockString
StockString = Session("Stocks")
ASP maintains session state by providing the client with a unique key assigned to the user when the session begins. This key is stored in an HTTP cookie that the client sends to the server on each request. The server can then read the key from the cookie and re-inflate the server session state.







