State Management 2 - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

State Management 2

Description:

Application contains a collection of data that is available across the entire ... Occurs when a new user accesses a page that's part of the application. ... – PowerPoint PPT presentation

Number of Views:126
Avg rating:3.0/5.0
Slides: 10
Provided by: haimin8
Category:

less

Transcript and Presenter's Notes

Title: State Management 2


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.
Write a Comment
User Comments (0)
About PowerShow.com