1 / 9

State Management 2

State Management 2. In ASP. Net. View State. View state uses a hidden field when the form is posted to store state on behalf of a client. Each time a page is posted to itself, the contents of the __VIEWSTATE field are sent as part of the post.

Download Presentation

State Management 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. State Management 2 In ASP. Net

  2. View State • View state uses a hidden field when the form is posted to store state on behalf of a client. • Each time a page is posted to itself, the contents of the __VIEWSTATE field are sent as part of the post. • The primary use of view state is for controls to retain their state across post-backs, but it can also be used as a mechanism for storing generic client-specific state between post-backs to the same page. • You can safely access the ViewState in your Load event handler.

  3. Application and Session Objects – Reloaded. • Application – contains a collection of data that is available across the entire application during the life of the application. • Session – contains data that is available across all pages accessed by a single user during a single session. • You can write code to respond to Application and Session events in the global.asax file.

  4. Session State • Session state is maintained on a per-client basis. • When a client first accesses any page in an application, an ASP.NET generated session ID is created. • Session state is used for things like: • Shopping carts, Viewing preferences, other • Session state is the most flexible and, in general, the most efficient means of maintaining client-specific state.

  5. Session Events

  6. Using the Session Object • Session state is maintained on behalf of each client within an ASP.NET application. • When a new client begins to interact with the application, a new session ID (or session key) is generated • The ID is associated with all subsequent requests from that same client. • The state is retained in memory on the server in the default session state configuration. • By default, the session key is retained on the client side in a cookie. (there is an alternative in cases where cookies do not work)

  7. Application State • Application state is where information that is global to the application may be stored. • For efficiency, this state is typically stored once and then read from many times. • Often used for application statistics variables or constant global data: • Number of users who have accessed site • Counts of different types of browsers • Can prefetch static data from a database or file • Should be used with care

  8. Application Events

  9. Using the Application Object • Application object is implicitly locked for you when data is read from or written to it. • May make more sense to avoid using application object and use data cache if you are just storing global constants. • Application object must be used if you are using shared, updatable data.

More Related