是否可以删除子域 cookie? [英] Is it possible to delete subdomain cookies?

查看:27
本文介绍了是否可以删除子域 cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果为子域 metric.foo.com 设置了 cookie,是否有办法删除 metric.foo.com cookie 对 www.foo.com 的请求?浏览器(至少是 Firefox)似乎忽略了域为 metric.foo.com 的 Set-Cookie.

If there is a cookie set for a subdomain, metric.foo.com, is there a way for me to delete the metric.foo.com cookie on a request to www.foo.com? The browser (at least Firefox) seems to ignore a Set-Cookie with a domain of metric.foo.com.

推荐答案

cookies 只能被创建它们的域读取,所以如果 cookie 是在 metric.foo.com 上创建的,它必须在相同的域下被删除域创建时.这包括子域.

Cookies are only readable by the domain that created them, so if the cookie was created at metric.foo.com, it will have to be deleted under the same domain as it was created. This includes sub-domains.

如果您需要从 metric.foo.com 中删除 cookie,但当前正在 www.foo.com 上运行一个页面,您将无法这样做.

If you are required to delete a cookie from metric.foo.com, but are currently running a page at www.foo.com, you will not be able to.

为此,您需要从 metric.foo.com 加载页面,或在 foo.com 下创建 cookie,以便它可以在任何子域下访问.或者使用这个:

In order to do this, you need to load the page from metric.foo.com, or create the cookie under foo.com so it can be accessable under any subdomain. OR use this:

Response.cookies("mycookie").domain = ".foo.com"

Response.cookies("mycookie").domain = ".foo.com"

...在创建它时,以及在删除它之前.

...while creating it, AND before you delete it.

..未经测试 - 应该可以工作.

..untested - should work.

这篇关于是否可以删除子域 cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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