These are two different things: one is SAVES [Response], the other is READS [Request]
in Cookie (talking computer science) :) you save a small file for a period of time that contains an object of type string
in the .NET framework you save a cookie :
HttpCookie myCookie = new HttpCookie("MyTestCookie"); DateTime now = DateTime.Now;
You wrote a cookie that will be available in one minute ... we usually do now.AddMonth (1) so that you can save the cookie for one whole month.
To extract the cookie , you use a request (you request), for example:
HttpCookie myCookie = new HttpCookie("MyTestCookie"); myCookie = Request.Cookies["MyTestCookie"]; // Read the cookie information and display it. if (myCookie != null) Response.Write("<p>"+ myCookie.Name + "<p>"+ myCookie.Value); else Response.Write("not found");
Remember:
To delete a cookie, there is no direct code, the trick is to Save the same cookie name with an expiration date that has already passed, for example now.AddMinutes (-1)
this will delete the cookie.
As you can see, every time a cookie expires, this file is automatically deleted from the system.
balexandre Feb 21 '09 at 23:57 2009-02-21 23:57
source share