C# – why not using Request.Cookies.Clear() in ASP.NET web forms

asp.netc++cookieswebforms

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!

Best Solution

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).