【发布时间】:2015-02-25 07:38:46
【问题描述】:
我的问题的部分答案似乎分布在多个帖子中,但到目前为止对我来说还没有奏效,所以我希望当这篇帖子得到回答时,它会形成更完整的指南
问题
我有一个 ASP.NET 网络表单应用程序 (W1),我想在一段时间内开始升级到一个单独的 MVC 应用程序 (M1)。包含 W1 的解决方案已升级到 4.5,并且已在解决方案中创建了 M1。 W1 使用 ASP.Net 成员框架。
测试用例
在 M1 中,我在 HomeController 的 About 页面中添加了 Authorize 属性
[Authorize]
public ActionResult About()
我在 M1 中添加了一个指向 about 页面的链接,该链接源自 W1 中要求用户登录的页面。
期待
我希望用户能够登录到 W1,单击指向 M1 关于页面的链接并自动登录到 M1。
配置
第1步我使用here 概述的方法从 W1 中提取了validationKey 和decryptionKey。虽然这似乎是一个合乎逻辑的步骤,但我不确定是否需要,因为不同的密钥仍然允许用户登录 W1。
第2步根据here和here的信息,经过大量调试,我修改了项目的Web.config文件部分,如下所示;
对于 W1:
<system.web>
<authentication mode="Forms">
<forms name="WRSAUTH"
loginUrl="~/Account/Login.aspx"
defaultUrl="Default.aspx"
protection="All"
timeout="60"
path="/"
domain=".localhost"
requireSSL="false"
slidingExpiration="true"
cookieless="UseCookies"
enableCrossAppRedirects="false" />
</authentication>
<machineKey validationKey="<ValidationKey>"
decryptionKey="<DecryptionKey>"
validation="SHA1"
decryption="AES"/>
<compilation debug="true" targetFramework="4.5">
<httpRuntime maxRequestLength="12288" />
</system.web>
对于 M1:
<system.web>
<authentication mode="Forms">
<forms name="WRSAUTH"
loginUrl="~/Account/Login"
defaultUrl="~/"
protection="All"
timeout="60"
path="/"
domain=".localhost"
requireSSL="false"
slidingExpiration="true"
cookieless="UseCookies"
enableCrossAppRedirects="false"/>
</authentication>
<machineKey validationKey="<ValidationKey>"
decryptionKey="<DecryptionKey>"
validation="SHA1"
decryption="AES"/>
<compilation debug="true" targetFramework="4.5"/>
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.webServer>
<modules>
<!--<remove name="FormsAuthentication"/>-->
</modules>
</system.webServer>
当前状态
当点击 W1 中指向 M1 关于页面的链接时,用户未获得授权并显示登录屏幕。
我在配置中有什么遗漏吗?
【问题讨论】:
标签: asp.net forms-authentication machinekey