Thursday, January 28, 2010

Difference between session and viewstate

1. Session state is a server based state management. It can be accessible from all pages in web application. It is scoped to current browser session only. It's structured as a key/value dictionary for storing session specific info that needs to be maintained between server round trips.

2. SESSION Variables are stored on the server, can hold any type of data including references, they are similar to global variables in a windows application and use HTTP cookies to store a key with which to locate user's session variables.

3. VIEWSTATE Variables are stored in the browser (not as cookies) but in a hidden field in the browser. Also Viewstate can hold only string data or serializable objects.

4. ViewState persist the values of controls of particular page in the client (browser) when post back operation done. When user requests another page previous page data no longer available.

5. SessionState persist the data of particular user in the server. This data available till user close the browser or session time completes.

6. Viewstate is particular to a control/page whereas session is for the whole application. You can access the session data stored in page A in page B but viewstate does not behave so.

7. ViewState is maintained at client side whereas session is maintained at server side

8. Since viewstate is maintained at client, it does not have a concept of expiry but session will expire after the stipulated time

9. You can enable/disable view state for specific controls but you can't do that for session.

No comments:

Post a Comment