Click here to Skip to main content
Click here to Skip to main content

all thing about cookies in asp.net c#

By , 9 Sep 2005
 

Introduction

a cookies are A very small text file placed on your hard drive by a Web Page server. It is essentially your identification card, and cannot be executed as code or deliver viruses. It is uniquely yours and can only be read by the server that gave it to you 

cookies purpose is To tell the server that you returned to that Web page

it may help you by saving your time

If you personalize pages, or register for products or services, a cookie helps Microsoft remember who you are.

Next time you return, we know to show you the information you requested. Or, when you register for another product or service, all you need to do is type in your e-mail address and a password. We then fill in any questions you've already answered. Of course, if you never register or leave personal information with Microsoft, then the server only knows that someone with your cookie has returned to the Web site. You are in charge of deciding whether we know anything about you. But the more you tell us about yourself, the more we can help you find information or products you want

how to use it

in order to handle a cookie in your system you should aware of 2 thing:

1-how to create them

2- how to delete them

so,first in order to create a cookie you have 2 variable must be defined as they are the cookie name and the duration of the cookie before it expired

  • in order to create a cookie it looks like this one

////////////SET THE COOKIE//////////////

Response.Cookies["test"].Value = UserName.Text ;

Response.Cookies["test"].Expires = DateTime.Now.AddYears(30);

where test is the cookie name

and the username.text is the textbox that will be used to define the cookies information

  • in order to delete a cookie use this

Response.Cookies["test"].Expires = DateTime.Now.AddYears(-30);

  • in order to check whether the cookie is found or not and retrieve the cookies information use this

/////////check to see if cookie presented//////////

if (Request.Cookies["test"] == null)

TextBox2.Text = "No cookie found";

else

TextBox2 .Text = Request.Cookies["test"].Value;

/////////END check to see if cookie presented//////////

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

A.Salem
Web Developer
Egypt Egypt
Member
if you need any details please contact me on protos_time_to_cry@hotmail.com

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 1memberjitendra kumar mahpatro24 Feb '12 - 17:17 
cookies properties is not explain
GeneralMy vote of 1memberPrince Antony G28 Nov '11 - 18:37 
its only basic things..give more details..
QuestionMore on cookiesmemberITFunda21 Jun '11 - 2:42 
Below are some more links related with cookies that is almost everything a normal developer should know.
 
How to create cookies in ASP.NET?

How to read cookies in ASP.NET?

How to set the expiration datetime for the cookies in ASP.NET?
How to read-write multi-valued cookies in ASP.NET?
How to limit the scope of cookies to a specific folder of the website in ASP.NET
 
Hope this would be useful. Smile | :)
 
Thanks
Questionwhat about securitymemberHuanacaraz21 Oct '10 - 5:57 
one must have parameter for cookie is 'HttpOnly' see HttpCookie class description on MSDN...
GeneralExellentmemberMember 411119213 Mar '10 - 15:38 
Brief and straight to the point, big kudos!
GeneralVery brief but greater usefulmemberJack987310 Aug '09 - 22:01 
Hi, thanks for writing about cookies.
Ur article is excellent as it is short enough to read easily and good enough to understand.
 
Thanks.
GeneralCookies - very usefulmemberyeswanths11 Nov '08 - 18:46 
hi,
this is very useful to us, salem keep writing article like this for various other web controls.
thank you
 
Yeswanth
Generalvery usefull,memberQurashi7 Jul '08 - 17:30 
thank you
Generalgoodmemberinamgul18 Mar '08 - 18:46 
the article describes a lot of in a much precise manner. Smile | :)
GeneralThank youmembergagy37911 Jul '07 - 10:01 
Nice article.
I implemeted mentioned personalizing throught cookies technique described here at http://www.najnakup.sk Smile | :)
 
IG

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 9 Sep 2005
Article Copyright 2005 by A.Salem
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid