Search Search

#1 worldwide
FREE Coding Lessons

since 1996
   THE BEST WAY to learn ASP & Asp.net!
Advertise Here!
click for details
Credits Host:
DiscountASP.net
Server Admin:
The "Team"
Contact Info.
Charles M. Carroll

my Blog
[prev. Lesson]  Global.asa, Sessions, Custom Stats Resources
     [next Lesson]  Pass Data w/Hidden Fields

State Management Methods, Pros and Cons by Charles Carroll

Several methods exist to maintain state. We will present a high-level summary here with advantages and drawbacks.

Method #1 Cookies

Pros: can be set for long periods of time. Wastes no server memory.

Cons: set on a machine. If user visits another machine their info is not there. If someone sits down at users machine, sites they visit may read cookie and it is NOT same person. Users may disable cookies.

Method #2 ASP Sessions

Pros: requires less lines of code than cookies. Easy to program.

Cons: wastes server memory. Evaporates and must be placed in durable storage if user changed session values. User who disable cookies can't have sessions.

Method #3 Hidden Fields

Pros: Works if user has disabled cookies.

Cons: adds Lots of code to each page. If someone invents a page that is not in your website and studies the HTML (where hidden fields are visible) they could feed incorrect hidden data to your form submits (negative numbers into shopping carts, $0 prices into shopping carts, etc.)

Method #4 Hidden Fields + Database

Pros: Works if user has disabled cookies.

Cons: adds Lots of code to each page. Since the hidden field is used to do a database retrieve, each page must hit a database.

Method #5 Homebrewed Sessions

Pros: Solves the problems of traditional ASP sessions.

Cons: Must build component or buy 3rd Party solutions (SASession from www.AspStudio.com for example).

Every site uses one or more of these methods to maintain state.

Chaz Wish List
Tall Tip $5
Grande Tip $20
Venti Tip $39
Tip Jar Thanks
2004 Thanks
2005 Thanks
HUGE Tip -love site