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"];
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.
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.
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="" />
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.
can be tampered creating a security hole.
2. Page performance decreases if you store large data, as the data are stored
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
Below is how you will actually implement
hidden field in a project
<asp:HiddenField ID="hiddenUserid" runat="server" />
cookie is a small bit of text that accompanies requests and pages as they go
between the Web server and browser.
No server resources are required as they are stored in client.
2. They are light weight and simple to use
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
3. Cookies can be tampered and thus creating a security hole.
4. Cookies can expire thus leading to inconsistency.
Below is sample code of
Request.Cookies.Add(New HttpCookie(“name”, “usrname”))