🦙
🦙
C# - How to delete cookie from .Net - Stack Overflow
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);