Chrome&amp ;;未设置响应Cookie IE浏览器 [英] Response Cookie not getting set by Chrome & IE

查看:136
本文介绍了Chrome&amp ;;未设置响应Cookie IE浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清为什么Chrome(26.0.1410.64)和IE10无法识别我在ASP.NET Web API控制器的响应中设置的Cookie。情况如下:

I'm trying to figure out why Chrome (26.0.1410.64) and IE10 don't seem to recognize the cookie I set in my response from an ASP.NET Web API controller. Here is the situation:

我的页面上有一个下拉菜单登录表单,该表单对我的Web API方法(通过HTTP POST)和该Web进行了ajax调用API方法返回一些JSON数据,并在响应中(使用HTTP标头)设置cookie。它在Firefox和Safari(即WebKit)中完美运行,但在Chrome或IE中则无法正常运行。 Chrome和IE似乎完全忽略了响应中发送回的Cookie。我已经验证(使用Fiddler),该cookie是根据响应发送回的,所以我知道它在那里-我不知道为什么IE10和Chrome不会将它捡起。

I have a drop-down menu login form on my page that makes an ajax call to my Web API method (via HTTP POST) and that Web API method returns some JSON data and also sets a cookie in the response (using the HTTP headers). It works perfectly in Firefox and Safari (so, WebKit) but not in Chrome or IE. Chrome and IE appear to completely ignore the cookie that's sent back in the response. I've verified (using Fiddler) that the cookie is sent back on the response so I know it's there - I can't figure out why IE10 and Chrome don't pick it up though.

有什么想法吗?

推荐答案

所以我发现了这个问题,这与Chrome和IE10如何处理ajax请求中的响应Cookie有关系吗?尽管这不是我真正想接受的解决方案。我想我只需要处理它,并始终使用Firefox在我的本地计算机上测试该站点。

So I figured out the issue, although it's not something I really would like to accept as a solution. I guess I will just have to deal with it and always test the site on my local machine using Firefox.

所以这是问题所在:

当我通过本地计算机上的Visual Studio和IIS在本地运行我的网站时,它会在 http:// localhost:1839 / 。出于某种原因,当IE10和Chrome处于 localhost时,ajax cookie会被IE10和Chrome忽略,而当它是真实的主机名或IP地址时,它就不会被忽略。因此,如果我编辑主机文件并创建一个诸如localhost.com之类的通用条目,并将其指向127.0.0.1:1839,那么IE和Chrome(以及Firefox也是如此)一切正常。

When I run my site locally by running it from Visual Studio and IIS on my local machine, it creates a website at an address like http://localhost:1839/. For some reason, ajax cookies get ignored by IE10 and Chrome when it's "localhost" - but not when it's a real-looking host name or IP Address. So if I edit my host file and create a generic entry like localhost.com and point it at 127.0.0.1:1839 then everything works fine in IE and Chrome (and Firefox still as well).

当我使用 localhost:1839 地址时,ajax cookie仅在Firefox中起作用。

It's when I use the localhost:1839 address that ajax cookie only works in Firefox.

因此,我最终要做的是将网站部署到另一台测试IIS服务器(在另一台计算机上),我在本地主机文件中有一个test.mydomain.com条目-指向测试IIS服务器的IP地址。现在IE,Chrome和Firefox都接受来自这个伪造的 test.mydomain.com域的ajax cookie。

So what I ended up doing was deploying my website to a different test IIS server (on another machine) that I have a test.mydomain.com entry in my local host file for - that points to the test IIS server's IP address. Now IE, Chrome and Firefox all accept the ajax cookie from this faked "test.mydomain.com" domain.

因此,对于那些通过ajax请求发送回cookie的人-注意Chrome和IE的本地主机问题。

So for those of you sending cookies back on an ajax request - beware of this "localhost" issue with Chrome and IE.

这篇关于Chrome&amp ;;未设置响应Cookie IE浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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