3

我的问题的部分答案似乎分布在多个帖子中,但到目前为止对我来说还没有奏效,所以我希望当这篇帖子得到回答时,它将形成更完整的指南

问题

我有一个 ASP.NET webforms 应用程序 (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

我使用此处概述的方法从 W1 中提取了validationKey 和decryptionKey 。虽然这似乎是一个合乎逻辑的步骤,但我不确定它是否需要,因为不同的密钥仍然允许用户登录 W1。

第2步

按照此处此处的信息,经过大量调试后,我修改了项目的 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 关于页面的链接时,用户未获得授权并显示登录屏幕。

我在配置中缺少什么吗?

4

1 回答 1

5

终于让这个工作了!

1) 不能在本地使用 localhost 或 .localhost 设置为域

2)在W1中,需要将属性targetFramework="4.5"添加到httpRuntime

3)在W1中,需要<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />在AppSettings节点内添加(标签)

希望我花时间发布这个问题和答案对某人有所帮助。我在许多帖子中找到了这个解决方案的一部分,但这将它们汇集在一起​​​​。

于 2015-02-26T07:06:52.800 回答