Saturday, January 28, 2006

Maintain State (persistence) in ASP .NET

Here I described benefits and limitations of using various technique to store state:
These techniques are other than InProc and OutProc(SQL Server) in web.config file.

1. Hidden Fields
2. View State
3. Hidden Frames
4. Cookies
5. Query Strings

one by one ...

1. Hidden Fields:

Benifits:
A. All browser support Hidden Fields.
B. Simpler to implement. (HTML hidden type tag)
C. As data is cached on client side they work with web farms.
D. No server side resources allocated.

Limitations:
A. Page performances decreases if you store large amount of data in a page.
B. Not Secured.
C Accept only single value per tag.


2. View State:

Benefits:
A. No server resources allocated.
B. Simple to implement.
C. States are retained automatically. (You can control wise enable/disable viewstate as per requirement)
D. Values stored in encoded fashion. More secure than hidden fields.
E. Good for caching data in Web Farm. (Same as hidden fields, clientside)

Limitations:
A. Page performance and loading speed decreases if larger amount of data is stored. (Like Gridview data)
B. View state stores data in HTMl Hidden field on page so even if data is encoded not complete secure.


3. Hidden Frames:

Benefits:
A. You can cache more than one data field.
B. The ability to cache and access data items stored in different hidden forms.
C. The ability to access JScript variable values stored in different frames if they come from same site.

Limitations:
A. Not supported by all browsers.
B. Stored data can be tampered.


4. Cookies:

Benefits:
A. No server resources are required to store data.
B. Light weight and simple to use. (to Write and read)


Limitations:
A. Limited size to store data 4096 byte or 8192 bytes.
B. User can disable cookies.
C. Cookies can be tampered.
D. Cookies expiry leads towards inconsistency.


5. Query String:

Benefits:
A. No server resources required.
B. All browser supports.


Limitations:
A. Values directly visible to user.
B. Limit is upto 255 characters for most browsers. (URL Length)

1 comment:

Anonymous said...

This is really useful to me. Advantages and disadvantage gives good idea... to which is useful technique to maintain state.
Please I want also information regarding some outproc techniques in ASP.NET

Visitor Count: