Google-chrome – Chrome localhost cookie not being set

asp.netcookiesgoogle-chromesession

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?

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

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:

  • Setting the Chrome command line flag –enable-file-cookies [DOES NOT
    WORK]
  • Setting the cookie to HttpOnly [DOESN'T MATTER]
  • Changing Expiration to Session or to a Date… [DOESN'T MATTER]
  • Changing the Cookie Path to Root (/) or to anything else [DOESN'T MATTER]

So what does matter? 🙂

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

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

Thanks!

Alex

Best Answer

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

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