Chapter 5: Managing Client State


Overview

One of the unique opportunities for members of the ASP.NET team is reviewing the architecture design for customers, which is beneficial not only for the customer but also for us. The customer gets validation and critical feedback about their design, and we get first-hand knowledge of usage scenarios that influence decisions for the technologies we build.

A common best practice that we advocate is to factor application and client state management into the solution early in the design. State management requires developers to plan for a Web server farm and to understand and adhere to specific design patterns. For example, out-of-process session state requires that the data stored be serializable by the binary serializer. In total, there are seven different techniques for managing state in ASP.NET, which are described in Table 5-1. In this chapter, we’re going to examine managing state that is stored for clients. In Chapter 6, we’ll examine application and request state.

Table 5-1: Techniques for Managing State in ASP.NET

Type of State

Applies to

Description

Session

Client

State stored within the application’s memory or outside of the application’s memory (out of process) and available only to the user who created the data.

ViewState

Client

State stored within embedded <input type=“hidden”> HTML elements for pages that post back to themselves.

Cookie

Client

State stored in an HTTP cookie on the client’s machine. Accessible until the cookie is expired or removed.

static variables

Application

Static member variables are declared in global.asax or from an HttpModule and are available anywhere within the application.

Application

Application

State stored within application’s memory and available anywhere within the application.

Cache

Application

State stored within application’s memory and available anywhere within the application. Cache additionally supports dependencies and other features to expire items from memory.

HttpContext

Request

State stored within HttpContext is accessible only for the duration of the request.

In this chapter, we’re going to examine managing state that is stored for clients. In Chapter 6, we’ll examine application and request state.

Working with and understanding how client state is used in the application is critical to putting a good design into practice. The most common type of client state is session state. Before we look at how session state is used in ASP.NET, let’s step back and review the history of session state, which will provide some context for understanding how it is used.




Microsoft ASP. NET Coding Strategies with the Microsoft ASP. NET Team
Microsoft ASP.NET Coding Strategies with the Microsoft ASP.NET Team (Pro-Developer)
ISBN: 073561900X
EAN: 2147483647
Year: 2005
Pages: 144

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net