1. Back To Blog

.NET architecture interview questions : - What are benefits and Limitation of using Viewstate, hidden frames and Cookies?

Following are the benefits of using Viewstate:-

  • No server resources are required because state is in a structure in the page code.

  • Simplicity.

  • 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();

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.

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.

  • Some users disable their browser or client device's ability to receive cookies, thereby limiting the use of cookies.

  • 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"))

Also click and see the following ASP.NET interview questions video on distinguishing between session and viewstate

Shiv Prasad Koirala

Visit us @ www.questpond.com or call us at 022-66752917... read more

We are on Social