Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between SessionState and ViewState?

What is the difference between SessionState and ViewState in ASP.NET?

like image 224
Natrium Avatar asked Apr 09 '09 09:04

Natrium


People also ask

Which is better ViewState or session?

Viewstate is more durable, since it's maintained by the user's browser. So even if a user sits on a page for an hour, then clicks somewhere, the page will still maintain the viewstate, while the Session will probably have expired.

What is ViewState used for?

View state is used automatically by the ASP.NET page framework to persist information that must be preserved between postbacks. This information includes any non-default values of controls. You can also use view state to store application data that is specific to a page.

What is SessionState mode?

The InProc Session State Mode stores session data in a memory object in the application worker process (aspnet_wp.exe) in the application domain. It is usually the fastest, but more session data means more memory is used on the web server, and that can affect performance.

What is difference between session and application state?

"Application state" = the state of the application, which is the same for all users. "Session State" = state specific to this particular user session. Each user has separate session state.


1 Answers

Session State contains information that is pertaining to a specific session (by a particular client/browser/machine) with the server. It's a way to track what the user is doing on the site.. across multiple pages...amid the statelessness of the Web. e.g. the contents of a particular user's shopping cart is session data. Cookies can be used for session state.
View State on the other hand is information specific to particular web page. It is stored in a hidden field so that it isn't visible to the user. It is used to maintain the user's illusion that the page remembers what he did on it the last time - dont give him a clean page every time he posts back. Check this page for more.

like image 185
Gishu Avatar answered Sep 30 '22 19:09

Gishu