Why won't asp.net create cookies in localhost?

前端 未结 3 1686
难免孤独
难免孤独 2020-11-27 04:42

Okay, this is really kinda starting to bug me. I have a simple Web project setup located at: \"C:\\Projects\\MyTestProject\\\". In IIS on my machine, I have mapped a virtu

3条回答
  •  伪装坚强ぢ
    2020-11-27 05:01

    The cookie specs require two names and a dot between, so your cookiedomain cannot be "localhost". Here's how I solved it:

    1. Add this to your %WINDIR%\System32\drivers\etc\hosts file: 127.0.0.1 dev.livesite.com

    2. When developing you use http://dev.livesite.com instead of http://localhost

    3. Use ".livesite.com" as cookiedomain (with a dot in the beginning) when creating the cookie. Modern browsers doesn't require a leading dot anymore, but you may want to use anyway for backwards compability.

    4. Now it works on all sites:

      • http://dev.livesite.com
      • http://www.livesite.com
      • http://livesite.com

提交回复
热议问题