by vamsikrishna   on Jul 03, 2014   Category: ASP.NET  | Level: Intermediate  |  Views: 1242    |  Points: 100   
Like this article? Bookmark and Share:
When user visit a website for the first time a .txt file sent to users web browser and stored in a user system in a particular location this text file termed as cookies.


Here I am Explaining about Cookies.

What is cookies?

When user visits a website for the first time a .txt file is sent to user's web browser and stored in a user system in a particular location, This text file is termed as cookie.

Use Of Cookies?

The main purpose of cookies is to know the user who visited websites.  For instance, you can also save a small piece of information inside cookies.

You might have seen almost every website login page having one checkbox "Remember Me on this computer". These websites store the login information like username and password inside the cookies. So, next time when user logs in, the website retrieves the information from cookies and you will belogged in automatically.

Types Of cookies:

1) Session CookiesThis cookie is stored temporary in the client machine. That means, when user closes the browser this session will be deleted from the client machine.This cookie is also called transient cookies.

2) Persistent CookiesPersistent cookies is stored on the client hard drive in a particular location until it is not expired. That means persistent cookies hold the informationuntil its expiry date and time.

Lets see how to work with cookies.

Like every Server side programming language ASP.NET also have Cookies class to deal with cookies.

To assign the value into cookies

HttpCookie myCookie =new HttpCookie("myCookie");//Create the instance of HttpCookie class

myCookie.Values.Add("username","MyUserName");// Add Key and its value to Cookies

myCookie.Values.Add("password","MyPassword");// add Another key and value.

We have stored the value into cookies now we will see how to retrieve value from cookies

To retrieve the value from Cookies

HttpCookie cookie =Request.Cookies.Get("myCookie");

string UserName =cookie.Values ["username"];

string Password =cookie.Values ["password"];

Like this article? Bookmark and Share:

Most viewed Articles

User Comments

  Re :cookies   
Posted by webspidy
on 7/3/2014 5:19:49 AM
Points : 10

Hi Vamsikrishna , this is very useful for beginners. thanks.

Submit feedback about this article

Please sign in to post feedback

Latest Posts