What are benefits and Limitation of using Viewstate for state management?
Following are the benefits of using Viewstate:-
- No server resources are required because state is in a structure in the page code.
- States are retained automatically.
- The values in view state are hashed, compressed, and encoded, thus representing a higher state of security than hidden fields.
- View state is good for caching data in Web frame configurations because the data is cached on the client.
Following are limitation of using Viewstate:-
- Page loading and posting performance decreases when large values are stored because view state is stored in the page.
- Although view state stores data in a hashed format, it can still be tampered because it is stored in a hidden field on the page. The information in the hidden field can also be seen if the page output source is viewed directly, creating a potential security risk.
Below is sample of storing values in view state.
this.ViewState[“EnterTime”] = DateTime.Now.ToString();
How can you use Hidden frames to cache client data?
This technique is implemented by creating a Hidden frame in page which will contain your data to be cached.
<FRAME src=”data_of_hidden_frame.html” frameborder=”0″ noresize scrolling=”yes”>
Above is a sample of hidden frames where the first frame “data_of_frame1.html” is visible and the remaining frames are hidden by giving whole col section to first frame. 100 % is allocated to first frame and remaining frames thus remain hidden.
What are benefits and limitations of using Hidden frames?
Following are the benefits of using hidden frames:
- You can cache more than one data field.
- The ability to cache and access data items stored in different hidden forms.
- The ability to access JScript® variable values stored in different frames if they come from the same site.
The limitations of using hidden frames are:
- Hidden frames are not supported on all browsers.
- Hidden frames data can be tampered thus creating security hole.
What are benefits and limitations of using Cookies?
Following are benefits of using cookies for state management:-
- No server resources are required as they are stored in client.
- They are light weight and simple to use
Following are limitation of using cookies:-
- Most browsers place a 4096-byte limit on the size of a cookie, although support for 8192-byte cookies is becoming more common in the new browser and client-device versions available today.
- Cookies can be tampered and thus creating a security hole.
- Cookies can expire thus leading to inconsistency.
Below is sample code of implementing cookies
Request.Cookies.Add(New HttpCookie(“name”, “user1”))
See following video on importance of session and viewstate: –
Click and see here for more step by step learning on ASP.NET.