State Management in ASP.NET Basic concepts

(I). Client Side State Management

This stores information on the client's computer by embedding the information into a Web page, a uniform resource locator(url), or a cookie. The techniques available to store the state information at the client end are listed down below:

1). View State – Asp.Net uses View State to track the values in the Controls. You can add custom values to the view state. It is used by the Asp.net page framework to automatically save the values of the page and of each control just prior to rendering to the page. When the page is posted, one of the first tasks performed by page processing is to restore view state.

2). Control State – If you create a custom control that requires view state to work properly, you should use control state to ensure other developers don’t break your control by disabling view state.

3). Hidden fields – Like view state, hidden fields store data in an HTML form without displaying it in the user's browser. The data is available only when the form is processed.

4). Cookies – Cookies store a value in the user's browser that the browser sends with every page request to the same server. Cookies are the best way to store state data that must be available for multiple Web pages on a web site.

5). Query Strings - Query strings store values in the URL that are visible to the user. Use query strings when you want a user to be able to e-mail or instant message state data with a URL.

Advantages:-
a. Better Scalability:
b. Supports multiple Web servers:



(II). Server Side State Management

1). Application State - Application State allows to store application specific information is available to all pages, regardless of which user requests a page.

Three Events you can use to initialize Application variables

a. Application_Start: Raised when the application starts. This is the perfect place to initialize Application variables.

b. Application_End: Raised when an application shuts down. Use this to free application resources and perform logging.

c. Application_Error: Raised when an unhandled error occurs. Use this to perform error logging.


2). Session State – Session State information is available to all pages opened by a user during a single visit. You can use session state to store user-specific information.

Advantages:-
a. Better security
b. Reduced bandwidth

More Info:-
http://msdn.microsoft.com/en-us/library/75x4ha6s.aspx
http://msdn.microsoft.com/en-us/library/z1hkazw7.aspx
http://www.dotnetfunda.com/articles/article61.aspx

No comments:

Post a Comment