且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用 asp.net mvc 3 和 c# 清除 cookie?

更新时间:2023-02-14 20:11:18

离你很近了.您需要使用 Response 对象写回浏览器:

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 );
}

有关 MSDN 的更多信息,如何:删除 Cookie.

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