|
ViewState |
Query String |
Custom Cookies |
Session State |
Application State |
Data types supported |
All.NET data types which are serializable |
Part of string data. |
String data. |
All.NET data types which are serializable. Nonserializable types are also supported in some cases. |
All .NET data types. |
|
|
|
|
|
|
Storage location |
A hidden field in the current web page. |
The browser's URL string. |
The client's computer (in memory or a small text file, depending on its lifetime settings). |
Server memory or a dedicated database, depending on the mode |
Server memory. |
|
|
|
|
|
|
Lifetime |
Retained permanently for postbacks to a single page. |
Lost when the user enters a new URL or closes the browser. However, can be stored and can persist between visits. |
Set by the programmer. It can be used in multiple pages and it persists between visits. |
Times out after a predefined period (usually 20 minutes but can be altered globally or programmatically). |
The lifetime of the application (typically, until the server is rebooted). |
|
|
|
|
|
|
Scope |
Limited to the current page. |
Limited to the target page. |
The whole ASP.NET application. |
The whole ASP.NET application. |
The whole ASP.NET application. Unlike most other types of methods, application data is global to all users. |
|
|
|
|
|
|
Security |
Tamper-proof by default but easy to read. You can use the Page directive to enforce encryption. |
Clearly visible and easy for the user to modify. |
Insecure and can be modified by the user |
Secure, because data is never transmitted to the client. However, subject to session hijacking if you don't use SSL. |
Very secure, because data is never transmitted to the client. |
|
|
|
|
|
|
Performance
|
Storing a large amount of information will slow transmission but will not affect server performance. |
None, because the amount of data is trivial. |
None, because the amount of data is trivial. |
Storing a large amount of information can slow down the server severely, especially if there are a large number of users at once, because each user will have a separate set of session data. |
Storing a large amount of information can slow down the server, because this data will never time out and be removed. |
|
|
|
|
|
|
Mostly used areas |
Page-specific settings. |
Sending a product ID from a catalog page to a details page. |
Personalization preferences for a website. |
Store items in a shopping basket. |
Storing any type of global data. |