Remember Me
forgot your password?

How to Choose From Viewstate, Session, Application, Cache, and Cookies

 

Problem with Web Applications

Web Applications are natively statesless, means once a web page renders from server to client, nothing remains on server and the next time user submits the page you have to load all values and create the page again.

 

ASP.NET provides multiple simple solutions to this problems like:




  • Viewstate



  • Session Variables



  • Application Variables



  • Cache



  • Cookies




 

Now the question arises that when to use what?

 

1- Viewstate

Viewstate is a hidden fields in an ASP.NET page, contains state of those controls on 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" );

Viewstate should be used when you want to save a value between diferent roundtrips of a single page as viewstate of a page is not accessible by another page.

Because Viewstate renders with the page, it consumes bandwith, so be careful to use it in applications to be run on low bandwith.

 

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 retrive user specefic information required on multiple pages.

Session variables consumes server memory, so if your may have a huge amount visiters, use session very carefully and instead of put large values in it try to put IDs and references

 


3- Application variables

Application variables are shared variables among all users of a web application

Application variables behave like static variables and they are substitute of static variables as static variables are stateless in web applications

Only shared values should be persisted in Application variables, and as soon as they are not in use they should be removed explicitly.

 


4- Cache

Cache is probably the least used state feature of ASP.NET.

Cache is basically a resource specific state persistence feature, means unlike 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



6- 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.

Because cookies have been saved at client side, they do not create performance issues but may create security issues as they can be hacked from browser.

 


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

Ahmed Siddiqui

Seasoned Microsoft Certified Professional having seven years of experience in analysis, design, and development of enterprise applications; utilizing true world class software development patterns & practices.

Rate this Article: 0 / 5 stars - vote(s)
Print Email Re-Publish

Add new Comment



Captcha

  • Latest Programming Articles
  • More from Ahmed Siddiqui

Professional Web Site Development - The Need of the Hour

By: Arun Kumar | 23/12/2009
Web based development firms are now outsourcing their projects to their offshore development facilities where cost of product development is comparatively lower. For all types of web based solutions, the offshore destinations have therefore been a very great place for all clients now.

Flash Animation Development: Affording a Sophisticated Programming Environment to Animators

By: Arun Kumar | 23/12/2009
With competition fast creping into the cyber world website owners are having a tough time to score a point over their competitors. The days when websites were developed just to maintain a web presence are over. Now every site owners are looking at techniques which can increase the number of their sites’ users.

ASP Reports

By: chaudhary fahim | 22/12/2009
Report generation is the important phase for the development of enterprise application.

Hire PHP Expert

By: linksswap | 22/12/2009
(Web Art Sense) PHP enabled websites are making the businesses run online. But what it takes to develop such powerful open source websites? Have you ever seriously thought on it? Open source technology is the advanced technology that allows customized web development operations. PHP websites are developed by team of experts. The team is divided into different groups that look into different aspects of website development.

Build Robust Web Applications using Spring Persistence with Hibernate

By: Swati | 22/12/2009
Packt is pleased to announce a new book, Spring Persistence with Hibernate that helps explore the features of Hibernate and helps developers integrate it with Spring to design their applications effectively. Written by Ahmad Seddighi, this book helps developers build and run persistence solutions for their enterprise Java applications using Spring and Hibernate frameworks.

iPhone Web Development Company: Helping You Get the Best of Web Applications

By: Arun Kumar | 22/12/2009
One gadget that has stunned the entire pool of gadget freaks through its awe-inspiring features and looks is the exquisite iPhone, a gem of a product from the Apple stable. It’s a device that everyone would like to touch, everyone would love to explore!

Joomla – Best Open Source Content Management System You Can Get

By: ali momin | 21/12/2009
Joomla is an open-source content management system (CMS) used to make a websites. Open-source means all underlying code is offered for free use and modification. So, there may be many applications running in a Joomla-built website, but they are usually free software available to use or modify.

Know the knowledge about photo accessories

By: Henry Miller | 21/12/2009
Lots of photo accessories websites have large ranges of professional photography and photograhic equipments in the world market.

Submit Your Articles Free: Signup
Article Categories




Use of this web site constitutes acceptance of the Terms Of Use and Privacy Policy | User published content is licensed under a Creative Commons License.
Copyright © 2005-2008 Free Articles by ArticlesBase.com, All rights reserved. (0.11, 1, w3)