Thursday, January 15, 2009

State Mnagement in Asp.Net

Client side statemanagement (Part-2)

1. View state: It is a in built structure for maintaining the state of a page. Its purpose is to keep the state of controls during subsequent post backs by the same user. It indicates the state of an object at that particular instant of time. It is maintained using hidden fields.

a) As it is a client side technique it does not require server resources
b) It is a in built structure
c) It is little secured as the values in view state are hashed, compressed and encoded
a) As view state is stored in the page itself, if we store more information in view state it affects the performance of the page
b) As view state is stored in the page itself we can view its contents when we view the source code.

2. HiddenFields: This is used to store page specific information in hidden fields.
This used to store values in html form with out displaying it on the browser.
We can use these for the page which post backs to itself or to another page.

a) As it is a client side technique it does not require server resources.
b) Most Browsers support this technique
a) As Hidden Fields is stored in the page itself, if we store more information in
Hidden fields it affects page performance
b) Security is less as users can view the information in hidden fields when they
Open the source code.

3. Cookies: A cookie is a file stored on users computer containing information Specific one site. Values stored in a cookie are sent to the same server with every page request through browser. Means they are posted back and forth on every request. Generally frequently changing information will be kept in a cookie. Default life time of a cookie on user s machine is 100000 minutes.

a) It does not require server resources.
b) It is very simple to implement
c) Cookie can expire when browser session ends or it can stay permanently till we apply some expiration rules.
a) Security is less as users can manipulate cookies on their machines.
b) Most Browsers allows only cookie with a max size of 4096 bytes
c) As there is security threat some users may disable their machines capability of receiving cookies thus reducing its functionality.

4. Query Strings: Query string is the information which we see at the end of the pages Url. Generally it is used to place navigation specific information.
We can’t keep sensitive information using query string.

a) It Does not require server resources
b) It is very easy to implement
c) Most Browsers support this feature
a) There is a security risk as it is visible in the browsers address bar.
b) Using query strings we can’t place more information.(2083 character limit)

5. Control State: This is used to store custom control data between server trips.
This is used to store small amounts of information of a control between server trips.
By default it is stored in hidden fields on a page.

a) server resources are not required
b) Easy to implement.
c) We can’t turn off control state at the page level. So, it is more reliable
a) To use this we need to write code for saving and loading of control state.

Server side state management (Part-3)

In this type state information will be stored on the server side.

1. Application state: It is used to store application specific information. This is stored in the server memory. Information stored in application state is common to all users and all sessions. Generally data which does not change often is stored in the application state.

a) As it is common all sessions we can keep a single copy.
b) Easy to implement
a) We lose data stored in application state when the web server process Containing it is destroyed.
b)As values stored in application state is particular to one process other
Processes can’t use those values.
c) As it requires server resources it may effect the performance of the server
And the scalability of the application

2. Session State: It Contains Session specific information that needs to be maintained between multiple page requests and server round trips. A session starts when the user enters in to the web site and session ends when he/she leaves the web site( which is called user’s. session). So, Session state object is used to maintain that particular session values. If there are multiple users for a web site then each one will have their own session. Generally session state is used to store data which is sensitive and which changes frequently. It can configured in web.config file.

a)Easy to implement
b)Session state is suitable for multi computer and multi process settings.
c) We can use session with cookies or without cookies
a)As it is specific to a particular user session we need to maintain multiple Sessions for multiple users.
b)As it requires server resources it may effect the server performance.

3. Database support: This is mainly used in cases where you want to store more amount of information. Using this method for each request your application contacts the database.

a) We can store large amount of information
b) It provides more security
c) Using this option we can store data for longer time
d) It provides data consistency
a) As this stores state information in database it effects server performance.

No comments:

Post a Comment