已安装ACS,但MVC 4.0应用仍然重定向,无法找到login.aspx

bar*_*ilt 24 asp.net-mvc azure wif acs

首先发布stackoverflow,但我喜欢这个网站!...

我已经使用MVC 4成功创建了一个功能齐全的Azure混合模型应用程序.发布并且效果很好.现在我想将auth的ACS添加到我的站点.我已经按照所有步骤进行了操作,但是当我在模拟中运行应用程序时,它无法重定向到ACS并提供页面声明它无法找到login.aspx.

我创建了一个简单的网站解决方案,只是为了证明我的ACS设置正确并且工作得很好.我注意到这两个解决方案的web.config文件差别很大.

有人试过这样做吗?任何帮助,将不胜感激.

---------解决方案-----------

我终于把一切都搞定了. 关键是要删除WebMatrix.WebData引用,因为我不需要自己执行身份验证.以下内容来自MVC4发行说明.

当WebMatrix.WebData.dll包含在ASP.NET MVC 4应用程序的/ bin目录中时,它将接管表单身份验证的URL.将WebMatrix.WebData.dll程序集添加到应用程序(例如,在使用"添加可部署依赖项"对话框时选择"带有Razor语法的ASP.NET网页")将覆盖身份验证登录重定向到/ account/logon而不是/ account默认ASP.NET MVC帐户控制器所期望的/ login.

ast*_*kov 3

打开您的 web.config 文件。

找到身份验证节点。

将其更改为:

<authentication mode="Forms" />
Run Code Online (Sandbox Code Playgroud)

到:

<authentication mode="None" />
Run Code Online (Sandbox Code Playgroud)

如果没有帮助,请在这里评论,以及更改 web.config 后的结果是什么。

作为一个附带问题 - 您如何添加对 ACS 命名空间的引用 - 通过“右键单击 -> 添加 STS 引用”,或手动更改 web.config ?

确保所需的模块已注册到 Web 服务器:

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
      <add name="ClaimsPrincipalHttpModule" type="Microsoft.IdentityModel.Web.ClaimsPrincipalHttpModule, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler" />
      <add name="WSFederationAuthenticationModule" type="Microsoft.IdentityModel.Web.WSFederationAuthenticationModule, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler" />
      <add name="SessionAuthenticationModule" type="Microsoft.IdentityModel.Web.SessionAuthenticationModule, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler" />
    </modules>
   ...
 </system.webServer>
Run Code Online (Sandbox Code Playgroud)

另请确保您有 microsoft.identityModel 部分,并且其中有 federatedAuthentcation 节点:

<federatedAuthentication>
        <wsFederation passiveRedirectEnabled="true" issuer="https://[your_namespace].accesscontrol.windows.net/v2/wsfederation" 
                      realm="http://127.0.0.1:81/" requireHttps="false" />
        <cookieHandler requireSsl="false" />
</federatedAuthentication>
Run Code Online (Sandbox Code Playgroud)

其中“领域”应是真实方应用程序的有效 URL。而 requireHttps="false" 是为了简化开发过程。

当您在本地调试它时,请确保您正在运行云项目(它使用 IIS),而不是 Web 项目(它将使用 Cassini / webdevserver,它不理解 system.webServer 部分!)