I searched here on the stackoverflow about removing all cookies from site, but couldn't find a single answer suggesting the use of Request.Cookies.Clear()
method.
What's the difference between:
if (Request.Cookies["UserSettings"] != null)
{
HttpCookie myCookie = new HttpCookie("UserSettings");
myCookie.Expires = DateTime.Now.AddDays(-1d);
Response.Cookies.Add(myCookie);
}
and:
Request.Cookies.Clear();
Thanks in advance! and sorry for my bad language, English is not my native!
Calling Remove
or Clear
will remove it from the server side collection held by Request.Cookies (which is a copy of the cookies your client sent to you). However that does not cause the server to instruct the client browser to remove the cookie. To do that you need to set the timeout as you have indicated above (see MSDN - How To: Delete a Cookie for the official guidance).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With