Codechef4u is a community for computer professionals,by computer professionals,just like you; who loves sharing and helping each others,Join them
Share your post

Advantages and disadvantages of Session

ASP.NET session state enables you to store and retrieve values for a user as the user navigates ASP.NET pages in a Web application.


//store session value
Session["UserName"] = UsernameTextBox.Text;
//retrieve session value. 
var currentUser= (string)Session["UserName"];


1. It helps maintain user state and data all over the application.
2. It is easy to implement and we can store any kind of object.
3. Stores client data separately.
4. Session is secure and transparent from the user.


1. Performance overhead in case of large volumes of data/user, because session data is stored in server memory.

2. Overhead involved in serializing and de-serializing session data, because in the case of StateServer and SQLServer session modes, we need to serialize the objects before storing them.

Advantages and disadvantages of using Hidden fields.

Hidden fields technique is widely used in ASP.NET programing. Hidden fields are html input control with hidden type that store hidden data in the html.

<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" /> 


 1.  They are simple to implement.
 2.  As data is cached on client side they work with Web Farms.
 3. All browsers support hidden field.
 4.  No server resources are required.


1. They can be tampered creating a security hole.

2. Page performance decreases if you store large data, as the data are stored in
pages itself.

3. `Hidden fields do not support rich structures as HTML hidden fields are only
single valued. Then you have to work around with delimiters etc to handle
complex structures.

 Below is how you will actually implement hidden field in a project

<asp:HiddenField ID="hiddenUserid" runat="server" />

Advantages and disadvantages of using Cookies

A cookie is a small bit of text that accompanies requests and pages as they go between the Web server and browser.


1.  No server resources are required as they are stored in client.
2. They are light weight and simple to use


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

2.  Some users disable their browser or client device’s ability to receive cookies,
There by limiting the use of cookies.

3.  Cookies can be tampered and thus creating a security hole.

4.  Cookies can expire thus leading to inconsistency.

Below is sample code of implementing cookies

Request.Cookies.Add(New HttpCookie(“name”, “usrname”))