What is the Difference Between SessionState and ViewState in ASP.NET

In this short tutorial, we will explain main difference between SessionState and ViewState that you need to know.

Difference between SessionState and ViewState

In my opinion, following are few points that technically differentiate session state and view state:

ViewState SessionState
The view state is maintain in page level The session state is maintain in session level
Scope of a view state is specific to a page only Scope of a session state is for a user session
The ViewState is used to store data that can be used during postbacks for page level The SessionState is used to store data that can be used anywhere within website or web application in asp.net
The view state is a client side state management technique to store data The session state is a server side state management technique to store data
The ViewState of one page is not visible in another page which means when user requests another page, the previous page stored data will be no longer available to use The SessionState value is available in all pages within a user session which means the data will no longer available if user close the browser or session timeout occurs (usually 20min which is default for session)
The ViewState has no specific expiration date or time to wipeout stored data The SessionState will clear session when the current user close his web browser or session dies due to inactivity of the user within set timeout (default is 20min)

When to Use SessionState and ViewState?

If you want to access the stored data over website or web application, you should definitely go with session state, whereas if you want to access the stored data for a specific page only (which means persists during postbacks), go with view state.

Which One is More Secure?

SessionState is more secure as compared to ViewState because session state store data value on server side whereas in view state data value store in client side.

I hope by reading the above points, you will get better understanding of the main difference between viewstate and sessionstate in asp.net with its usage and security.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *