Cookies: - Cookies are little pieces of information
that a server stores on a browser. They are of two types
Temporary cookie: - They are also known as session
cookies. These are volatile in nature. When the browser is shutdown they are
Persistent cookie:- These may be called as permanent
cookies. These are especially saved in files. It may remain for a month or
Properties of cookies
Some properties of cookie
Name: - represent the name of cookie.
Name value: - represent a collection of key values of cookie
Domain: - represent the domain associated with a specific
Path: - the path associated with a cookie.
Expires: - expired time of cookie.
Hashkey: - identifies whether the cookie is a cookie dictionary.
Secure: - specifies whether the cookie is to be sent in an
encrypted connection or not.
Working with cookies
Cookies are send back and forth between a browser and
server. The server creates a cookie by using the set cookie header. Subsequent
request from the browser is send to the server in cookie header. Suppose the
server create a cookie
Set cookie: username=rajkumar; path=1;domain=abc.com;
expires=Friday, 19th august 20116:30:00GMT
The server creates the cookie named as username containing
the user information. Path identifies any requested page to the website, domain
identifies the specific website abc.com, expired identifies that this cookie
would be expired on the specific data mentioned.
After the server creates the cookie the response is send to
the server from the browser for each subsequent request to the webpage. The
reader sends in the format cookie: username=raj+kumar
The server is using set cookie reader. The browser is using
Creation and reading session cookies
The session cookies can be created by using the response
object and can be read by using the request object. The cookies properties of
the response and request objects contains instances of Httpcookies collection
class. Each cookie is created by using Httpcookie class.
For creating cookies
Dim cookies1 As New HttpCookie("raj", "kumar")
For reading cookies
Partial Class _Default
Protected Sub Button1_Click(ByVal
sender As Object,
ByVal e As
System.EventArgs) Handles Button1.Click
cookies1 As New
Protected Sub Button2_Click(ByVal
sender As Object,
ByVal e As
System.EventArgs) Handles Button2.Click
Dim s As String
For Each s In
Label1.Text += "<li>" & s
TextBox1.Text = ""
TextBox2.Text = ""
It is saved in a config file.it has a specific expiration
date. It is especially used to store information about userid, name of authenticated
For creating persistence cookie
Dim pcookie1 as New HttpCookie("user name"."ravi kumar")
For reading persistent cookie
Limitation of cookies: -
1.A cookie can store maximum of 4kb of data.
2.A cookie can contain only string values. It can contain
objects like dataset object.
3.A cookie is browser dependent.
4.Persistent cookie may be deleted before expiration date by
1. Cookies do not require any server resources since they are stored on the
2. Cookies are easy to implement.
3. You can configure cookies to expire when the browser session ends (session
cookies) or they can exist for a specified length of time on the client
computer (persistent cookies).
1. Users can delete a cookies.
3. Cookies exist as plain text on the client machine and they may pose a
possible security risk as anyone can open and tamper with cookies