Delete cookie issue in C#

civicwar

New Member
I'm trying to delete a cookie, however it doesn't get deleted. Here is the code I try to use.\[code\]Response.Write(Request.Cookies["dcart"].Expires);// Response 1/1/0001 12:00:00 AMResponse.Write(Request.Cookies["dcart"].Value);// Response 229884if (Request.Cookies["dcart"] != null){ HttpCookie myCookie = new HttpCookie("dcart"); myCookie.Expires = DateTime.Now.AddDays(-1d); myCookie.Valuehttp://stackoverflow.com/questions/13754541/= ""; Response.Cookies.Add(myCookie);}Response.Write(Request.Cookies["dcart"].Expires);// Response 1/1/0001 12:00:00 AMResponse.Write(Request.Cookies["dcart"].Value);// Response 229884\[/code\]When I retrieve the cookie again, nothing changes. I check w/ FireFox and Chrome same behavior. Interesting point is that expiration date shows correctly on the browsers but on the code.I tried followings and didn't work.
  • Set expiration day to (tomorrow) and again set it for yesterday.
  • Restart the browser (happens different browsers and people)
  • Set the value something
  • Use HttpContext.Current.Request.Cookies["dcart"]....
  • Request.Cookies["dcart"].Expires = DateTime.Now.AddYears(-10);
 
Back
Top