Docsity

ASP.NET State Management: Client and Server Techniques, Slides of Computer Programming

Partial preview of the text

Download ASP.NET State Management: Client and Server Techniques and more Slides Computer Programming in PDF only on Docsity!

ASP.NET State

Management

Lecture Overview

 Client state management options  Server state management options

Types of State Management

 ASP.NET offers two categories of state management  Pure client-side statement management  Server-side state management

Client State Management

(Introduction)

 View state  Control state  Hidden fields  Cookies  Query strings

State Management

( ControlState )

 The ControlState property allows you to persist information as serialized data  The wiring is not automatic  You must program the persisted data each round trip  The ControlState data is stored in hidden fields

State Management

(Hidden Fields)

 Use the HiddenField control to store persisted data  The data is stored in the Value property

 It’s simple and requires no server resources

Cookie Limitations

 While simple, cookies have disadvantages  A cookie can only be 4096 bytes in size  Most browsers restrict the total number of cookies per site  Users can refuse to accept cookies so don’t try to use them to store critical information

Cookies Members

 Use the Response.Cookies collection to reference a cookie  Value contains the cookie’s value  Expires contains the cookie’s expiration date  Cookies can also store multiple values using subkeys  Similar to a QueryString  It’s possible to restrict cookie scope by setting the Path property to a folder

Server State Management

Options

 Application state  Session state  Profile properties  Database support

Server State Management

HttpApplicationState applies to your entire application  HttpSessionState applies to the interaction between a user’s browser session and your application

 Page caching also relates to state management

The HttpApplicationState

Class (Members 1)

 The AllKeys property returns an array of strings containing all of the keys  Count gets the number of objects in the collection  Item provides read/write access to the collection

The HttpApplicationState

Class (Members 2)

StaticObjects returns a reference to objects declared in the global.asax file  tags with the scope set to Application  The Add method adds a new value to the collection  The Remove method removes the value associated with a key

Application State

(Best Practices)

 Memory to store application state information is permanently allocated  You must write explicit code to release that memory  So don’t try to persist too much application state information

 The Cache object, discussed later, provides alternatives to storing application state information

Profile Properties

 It’s a way to permanently store user-specific data  Data is saved to a programmer-defined data store  It takes quite a bit of programming  The whole thing is unique to windows