How do you clear cookies using asp.net mvc 3 and c#?

You’re close. You’ll need to use the Response object to write back to the browser:

if ( Request.Cookies["MyCookie"] != null )
{
    var c = new HttpCookie( "MyCookie" );
    c.Expires = DateTime.Now.AddDays( -1 );
    Response.Cookies.Add( c );
}

More information on MSDN, How to: Delete a Cookie.

Leave a Comment