未设置 Chrome 本地主机 cookie [英] Chrome localhost cookie not being set

查看:32
本文介绍了未设置 Chrome 本地主机 cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ASP.net 应用程序,它使用 cookie 来存储用户选择的语言.一切正常,除非我在本地主机上.用 127.0.0.1 替换 localhost 使它再次工作......为什么?

I have an ASP.net application that uses a cookie to store the user selected language. Everything works fine except when I'm on localhost. Replacing localhost by 127.0.0.1 makes it work again... why?

我看到了对 file://的预期限制,但实际上我找不到任何对 localhost 的预期限制的引用.

I saw intended restrictions to file:// but I can't actually find any reference to intended restriction to localhost.

我无法真正理解的是为什么为 localhost 域正确设置了 ASP.net 会话 (ASP.NET_SessionId) 和 ASP.net Forms Authentication Cookies (.FSAUTHSSO) 但我的 cookie 不是......为什么?!

What I can't really understand is why the ASP.net Session (ASP.NET_SessionId) and ASP.net Forms Authentication Cookies (.FSAUTHSSO) are correctly set for the localhost domain but my cookies aren't... why?!

我已经用谷歌搜索了很多,但没有任何效果:

I already googled a lot and nothing works:

  • 设置 Chrome 命令行标志 --enable-file-cookies [不工作]
  • 将 cookie 设置为 HttpOnly [无关紧要]
  • 将到期时间更改为会话或日期...[无关紧要]
  • 将 Cookie 路径更改为根 (/) 或其他任何内容[无关紧要]

那又有什么关系呢?:)

So what does matter? :)

为什么可以设置 ASP.net cookie 而我的不能?有什么区别?

And why can the ASP.net cookies be set and mine don't? What's the difference?

最后要提到的是,这也发生在 IE 上,但在 FF 上运行良好.

Last thing just to mention that this also happens on IE but works fine on FF.

谢谢!

亚历克斯

推荐答案

Cookie 专为二级及以下级别设计.一级域将不起作用.相反,您应该使用地址 http://127.0.0.1(如您所述),或者您可以编辑您的主机文件以映射带有 TLD 的不同 URL 指向地址 127.0.0.1,例如:

Cookies are designed for second level and down. First level domains will not work. Instead you should use the address http://127.0.0.1 (as you mentioned) or you could edit your hosts file to map a different URL with a TLD to the address 127.0.0.1 such as:

yoursite.tld   127.0.0.1

刚刚对此进行了进一步研究;找到了这个答案:具有显式域的 localhost 上的 Cookies

Just researched this further; found this answer: Cookies on localhost with explicit domain

这篇关于未设置 Chrome 本地主机 cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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