Response.Cookies.Clear()不起作用? [英] Response.Cookies.Clear() not working?

查看:598
本文介绍了Response.Cookies.Clear()不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想删除所有Cookie。我认为有两种方式:



1.

I want to delete all the cookies. I think there're 2 way:

1.

Response.Cookies.Clear();



2.


2.

string[] myCookie = Request.Cookies.AllKeys;
foreach (string cookie in myCookie)
{
     Response.Cookies[cookie].Expires = DateTime.Now.AddDays(-1);
}



结果只有方法2工作,为什么方法1不起作用?



MSDN说约 HttpCookieCollection.Clear():清除cookie集合中的所有cookie。

HttpCookieCollection.Clear方法 [ ^ ]为什么它不起作用?我认为它应该可行。


The result is only method 2 work, why method 1 doesn't work?

MSDN says about HttpCookieCollection.Clear() : Clears all cookies from the cookie collection.
HttpCookieCollection.Clear Method[^] Why it doesn't work? I think it should work.

推荐答案

清除响应的cookie不会影响存储在客户端上的cookie - 它只是指示响应不发送这些cookie给客户。



如果你想从客户端删除cookie,你必须将它设置为过期。

想一想:如果你有两个不同系统的cookie在同一个域上运行,你就不想要另一个清除cookie了!实际的cookie删除必须是明确的。
Clearing the cookies of the response doesn't affect the cookies stored on the client - it just instructs the Response not to send those cookies to the client.

If you want to remove a cookie from the client, you have to set it to expired as you are doing.
Think about it: if you have cookies from two different systems running on the same domain, you don;t want one clearing cookies for the other! Actual cookie removal has to be explicit.


这篇关于Response.Cookies.Clear()不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆