State Management 2: in ASP. Net
State Management 2: in ASP. Net
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.
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.
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.
Event Description
Session_OnStart Occurs when a new user accesses a page
that’s part of the application. Can be used to
initialize: session variables, session level
objects, and begin database connections.
Session_OnEnd Happens when a session times out. Can be
used to any final cleanup and to close a
database connection.
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)
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
Application Events
Event Description