Skip to main content David Edelstein's Blog

🦙
🦙

C# - How to delete cookie from .Net - Stack Overflow

Published: 2015-04-23
dave@edelsteinautomotive.com
David Edelstein

To remove a cookie, remove it from the response, then add a new cookie with a blank value that has already expired. I’m not sure why Response.Cookies.Remove doesn’t get this to work. But the following does:


HttpCookie currentUserCookie = HttpContext.Current.Request.Cookies["currentUser"];
HttpContext.Current.Response.Cookies.Remove("currentUser");
currentUserCookie.Expires = DateTime.Now.AddDays(-10);
currentUserCookie.Value = null;
HttpContext.Current.Response.SetCookie(currentUserCookie);

(via c# - How to delete cookie from .Net - Stack Overflow)

MSDN