我知道可以使用设置
在多个子域中共享Cookie<forms
name=".ASPXAUTH"
loginUrl="Login/"
protection="Validation"
timeout="120"
path="/"
domain=".mydomain.com"/>
在Web.config中。但是如何在本地机器上复制相同的东西。我在笔记本电脑上使用Windows 7和IIS 7。所以我有站点localhost.users /我的实际站点users.mysite.com localhost.host/用于host.mysite.com和类似的。
答案 0 :(得分:9)
localhost.users
和localhost.host
是跨域名。 Cookie不能跨域共享。
您可以像这样配置它,以便子域不同但根域保持不变:
users.localhost
host.localhost
现在将web.config中的cookie域设置为localhost
:
domain=".localhost"
并在c:\Windows\System32\drivers\etc\hosts
文件中添加以下两个条目:
127.0.0.1 users.localhost
127.0.0.1 host.localhost
现在,您将能够在users.localhost
和host.localhost
之间成功共享身份验证Cookie。
啊,不要忘记在自动构建过程中加入一步,将您的web.config值转换为正确的根域,然后再投放到生产环境中。
答案 1 :(得分:3)
这是对在Framework 4.5中运行并尝试与框架4及更低版本共享令牌的任何人的提醒,请注意这将导致您不会在任何4个及更低版本的应用程序上收到身份验证cookie。即:如果你的web.config
有:
<httpRuntime maxRequestLength="80480" targetFramework="4.5" />
您可以通过删除targetFramework="4.5"
属性来使其工作,但我不知道这样做是否有任何副作用:
<httpRuntime maxRequestLength="80480" />