State Management Priority

Viewstate
Session Variables
Application Variables
Cache
Cookies

Now the question arises that when to use what?
1- Viewstate
Viewstateis a hidden fields in an ASP.NET page, contains state of those controlson a page whose "EnableViewstate" property is "true".
You can also explicitly add values in it, on an ASP.NET page like:
Viewstate.Add( "TotalStudents", "87″ );
Viewstateshould be used when you want to save a value between differentroundtrips of a single page as viewstate of a page is not accessible byanother page.
BecauseViewstate renders with the page, it consumes bandwidth, so be carefulto use it in applications to be run on low bandwidth.
2- Session Variable
Session variables are usually the most commonly used.
When a user visits a site, it's sessions starts and when the user become idle or leave the site, the session ends.
Session variables should be used to save and retrieve user specific information required on multiple pages.
Sessionvariables consumes server memory, so if your may have a huge amountvisitors, use session very carefully and instead of put large values init try to put IDs and references
for more information  :- http://support.microsoft.com/kb/307598


3- Application variables
Application variables are shared variables among all users of a web application
Applicationvariables behave like static variables and they are substitute ofstatic variables as static variables are stateless in web applications
Onlyshared values should be persisted in Application variables, and as soonas they are not in use they should be removed explicitly.

4- Cache
Cache is probably the least used state feature of ASP.NET.
Cacheis basically a resource specific state persistence feature, meansunlike session it stick with resource instead of user, for instance:pages, controls etc.
Cache should be used or frequently used pages, controls, and data structures
Data cache can be used to cache frequently used list of values e.g. list of products

5- Cookies
Cookies are some values saved in browsers by the website to retrivbbe and use afterwards.
Usually cookies are used to help dynamic websites to identify visitors and retrieve their saved preferences.
Cookies are also used to facilitate auto login by persisting user id in a cookie save in user's browser.
Becausecookies have been saved at client side, they do not create performanceissues but may create security issues as they can be hacked frombrowser.

Finally remember the following points on your finger-tips:
Viewstate is bandwidth hungry
Session variables are memory hungry as per number of users
Applications variables are shared
Cache is memory hungry as per number of resources
Cookies are the least secure

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites