Professional Documents
Culture Documents
Cookies in
Cookies in
Cookies in
ASP.NET Cookies
Table of Contents
Introduction
What are Cookies ?
How Cookies are started ?
Advantages of Cookies
Disadvantages of Cookies
How to create cookies ?
How to read data from cookies ?
What is Persistent and Non Persistent Cookies ?
How to make Persistent Cookies ?
Where does cookies are stored in local Hard drive ?
How to remove a persistent cookies before it's Expiration time ?
How to control cookies Scope ?
Cookie Munging
o What is Cookie Munging ?
o Why we are using Cookie Munging in ASP.NET ?
o How Cookie Munging Works ?
o How to Implement Cookie Munging ?
Introduction
First of all I would like to thanks to all of readers who read my previous articles
and voted me. Wow.. What a great support I have got from you people. Again
thanks to Sean Ewington to start up with a very fantastic idea with Beginner's
Walk for Web Development article. I have written few articles for Beginners. I
really feel great when my "Beginner's Guide to View State" article displayed in
Home Page "Editor's Choice" section. Following are articles that I have
written so far for the Beginner's
Cookies, Session, and Application Object are in Queue. Now, It's time for
reading about cookies. I have spend a lots of times to prepared this article. And
you will be very surprised to know that Introduction part is the last topic which I
am writing before posting article. I have read many articles, books before
writing this article. Done some hands on also. Hope I have explained this well ,
and hope you people also like it. Please give your suggestion and feedback.
What are Cookies ?
-2Cookies are the small files that are created on the client's system or client
browser memory (iftemporary). Its use for State management that I have
already discuss on my view state article. So we can store small piece of
information in a client system and we can use it when we needed. Most
interesting thing is that Its works transparently with the user. It can be easily
used any where of you web application. Cookies store information in a plain
text format. If any web application using cookies, Server send cookies and
client browser will store it. The browser then returns the cookie to the server at
the next time the page is requested. The most common example of using a
cookie is to store User information, User preferences , Password Remember
Option etc. Cookies has many advantages and disadvantages. I will comes to
this points , but first have a look how cookies are started.
How Cookies are started ?
When client request to the server, server send the cookies into client . The same
cookies can be referred for subsequent request. As for example,
if codeproject.com stores session id as a cookies, when any client hits first
times on the server, server generates the session id and send it as a cookies to
client. [As given in Fig 1.0]
-3-
Disadvantages of Cookies
Main disadvantages of cookies are:
Its store data in a simple text format. so it's not secure at all.
There is a size limit of cookies data ( 4096 bytes / 4KB).
-4Now , have a look, on the code , that how can we create a cookies and add it
with web response .3
The cookies which has been created will persist , until browser has been closed.
we can persist the cookies. But how? Just after few point I have discussed it.
How to Read data from cookies ?
Now , its times to retrieve data from cookies. Ok, before reading cookies, first
of all we need to check whether a cookies was found or not. "Its always good
practice to check cookie before read it, because is browser is disable cookies.
Persistent Cookies
Non Persistent Cookies
-6-
-8-
-9-
First option will Accepts All cookies and Last Option Will block all cookies. you
can get the details of those settings while scrolling the bar.