Answer cookie cookie not set by Chrome and IE

I am trying to understand why Chrome (26.0.1410.64) and IE10 do not seem to recognize the cookie that I set in my answer from the ASP.NET web API controller. Here is the situation:

I have a dropdown menu entry form on my page that makes an ajax call for my web API method (via HTTP POST) and that the Web API method returns some JSON data and also sets a cookie in the response (using HTTP headers). It works fine in Firefox and Safari (like WebKit), but not in Chrome or IE. Chrome and IE seem to completely ignore cookies, which are sent back in response. I checked (using Fiddler) that the cookie was sent back to the answer, so I know it there - I can’t understand why IE10 and Chrome do not pick it, though.

Any ideas? Is this related to the way Chrome and IE10 handle response cookies in ajax requests?

+6
source share
3 answers

So, I understood the problem, although this is not something that I really would like to take as a solution. I think I just have to deal with this and always test the site on my local machine using Firefox.

So here is the problem:

When I launch my site locally, running it from Visual Studio and IIS on my local computer, it creates a site at an address, for example, http://localhost:1839/ . For some reason, the ajax cookie is ignored by IE10 and Chrome when it is "localhost", but not when it is the real host name or IP address. Therefore, if I edit the host file and create a shared entry, for example localhost.com, and point it to 127.0.0.1:1839, then everything will work fine in IE and Chrome (and Firefox doesn't care).

This is when I use the localhost:1839 address that the ajax cookie only works in Firefox.

So, what I finished is deploying my website to another IIS test server (on another computer), in which I have a test.mydomain.com entry in my local host file for - this points to the IP address of the test IIS- server, Now IE, Chrome and Firefox accept ajax cookies from this fake domain "test.mydomain.com".

So, for those of you who send cookies back on ajax request, be careful with this "localhost" issue with Chrome and IE.

+17
source

The domain in the set cookie is most likely against the use of localhost. If you edit the hosts file and add an alias, it will force test.mydomain.com to point to your local computer:

  • Inside c: \ windows \ System32 \ drivers \ etc \ hosts add the following:
    • 127.0.0.1 test.mydomain.com
  • Launch the web server in Visual Studio
  • Close all browsers, then download test.mydomain.com
+2
source

It made me dunk for an hour until I found this answer. I tested a Tornado-based server that implements Posthout authentication callback. The server used HTTPRequest.set_secure_cookie (), which Chrome did not take into account. Using Firefox circumvented this issue, as did testing with Chrome on a different desktop.

+1
source

Source: https://habr.com/ru/post/943818/


All Articles