【发布时间】:2013-03-24 19:58:46
【问题描述】:
我正在尝试将表单身份验证从根应用程序共享到在虚拟目录中运行的子应用程序。我在子站点中的身份验证遇到问题。
在父应用程序中,一切都按预期工作。
我有以下设置:
父应用:
-
网址:
http://localhost:1336/ <forms loginUrl="~/account/sign-in" protection="All" timeout="30" name=".MYAPPLICATION" path="/" requireSSL="false" slidingExpiration="true" cookieless="UseDeviceProfile" enableCrossAppRedirects="true" defaultUrl="/" />
虚拟目录:
-
网址:
http://localhost:1336/subsite <forms loginUrl="/account/sign-in" protection="All" timeout="30" name=".MYAPPLICATION" path="/" requireSSL="false" slidingExpiration="true" cookieless="UseDeviceProfile" enableCrossAppRedirects="true" defaultUrl="/" />
当我尝试http://localhost:1336/subsite 时,我得到以下流程:
-
GET for
http://localhost:1336/subsite-> 302 到 /account/sign-in?ReturnUrl=%2fsubsite (看起来不错) - 输入用户名/密码
-
POST 到
http://localhost:1336/account/sign-in?ReturnUrl=%2fsubsite-> 302 /subsite (很好,授权看起来很成功) -
GET for
http://localhost:1336/subsite-> 302 到 /account/sign-in?ReturnUrl=%2fsubsite (即子网站认为其未通过身份验证)
我还可以在浏览器的列表中看到 cookie(所以它确实存在)
我的配置有什么问题导致我的子网站无法共享父 cookie?
我在 IISExpress 上运行它
【问题讨论】:
-
你在web.config中设置了通用的machineKey吗?
-
@davea 我的理解是,仅当站点位于不同的物理机器上时才需要这样做。这些都在我的开发箱上。不是这样吗?
-
我认为这不是真的。我正在做一个相反的项目。 1个主机,主域和子域(管理员和客户端),我们不尊重登录以保持分裂。我们不必配置此行为。这是默认的。因此,我认为从同一台机器托管并没有什么不同。
-
@davea 好的酷,我给你一个裂缝:)
-
也对此感兴趣。
标签: asp.net asp.net-mvc forms-authentication