错误 – SignInResponse消息可能只能在当前的Web应用程序–MVC 2.0应用程序中redirect

我有一个情况,我们有一个MVC 2应用程序(我尝试了一个基本的MVC 2应用程序没有任何额外的东西,仍然是同样的问题),并使用adfs 2authentication我的用户。

所以..现在我进入我的应用程序,我得到下面.. ID3206:SignInResponse消息可能只能在当前的Web应用程序中redirect:'/ [app]'是不允许的。 说明:执行当前Web请求期间发生未处理的exception。 请查看堆栈跟踪,了解有关错误的更多信息以及源代码的位置。 exception详细信息:Microsoft.IdentityModel.Protocols.FederationException:ID3206:SignInResponse消息只能在当前Web应用程序内redirect:不允许使用“/ [app]”。

我已经阅读了大部分的博客,并张贴到一个..

<federatedAuthentication> <wsFederation passiveRedirectEnabled="true" issuer="https://auth.[domain]/adfs/ls/" realm="https://[development domain]/[app]/" requireHttps="true" /> <cookieHandler requireSsl="true" /> </federatedAuthentication> <audienceUris> <add value="https://[development domain]/[app]/" /> </audienceUris> 
  1. 我在这个领域和观众里面都有一个尾随的斜线。
  2. 我已经添加了他对Application_BeginRequest的build议 – 然后,我将代码复制到[开发域],因为这是证书所在的地方。然后它就陷入了一个无限循环。
  3. 我也检查了日内瓦服务器上的依赖方..标识符和端点(POST)都是https:// [开发域名] / [app] / – 再次以斜线

我认为这是一个MVC应用程序的问题,我已经创build了大量的声明感知网站,并得到我的声明等default.aspx页面上。 我的想法是,与MVC应用程序有关的路由以某种方式发布错误?

任何帮助真的apprecaited我看着这个安静了一阵子,现在没有用。

Ĵ

我一直在把这件事撕成碎片。 我也有我的configuration中指定的尾部斜线。 原来,在我的情况下,导航到我的应用程序在浏览器中的尾部的斜杠像这样:

HTTP://本地主机/ MyApp的/

将工作,而

HTTP://本地主机/ MYAPP

将不会。

如果我能够找出更多的理由来解释这种情况,我将在这里再补充一些背景知识。

我重写了WSFederationAuthenticationModule子类上的RedirectToIdentityProvider 。 在redirect到STS之前,这只发生一次。 你必须告诉configuration文件使用这个类FixedWSFederationAuthenticationModule而不是默认的WSFederationAuthenticationModule

 public class FixedWSFederationAuthenticationModule : WSFederationAuthenticationModule { public override void RedirectToIdentityProvider(string uniqueId, string returnUrl, bool persist) { //This corrects WIF error ID3206 "A SignInResponse message may only redirect within the current web application:" //First Check if the request url doesn't end with a "/" if (!returnUrl.EndsWith("/")) { //Compare if Request Url +"/" is equal to the Realm, so only root access is corrected //https://localhost/AppName plus "/" is equal to https://localhost/AppName/ //This is to avoid MVC urls if (String.Compare(System.Web.HttpContext.Current.Request.Url.AbsoluteUri + "/", base.Realm, StringComparison.InvariantCultureIgnoreCase) == 0) { //Add the trailing slash returnUrl += "/"; } } base.RedirectToIdentityProvider(uniqueId, returnUrl, persist); } } 

这个代码照顾(把它放在global.asax中):

 private void Application_BeginRequest(object sender, EventArgs e) { // This corrects WIF error ID3206 "A SignInResponse message may only redirect within the current web application: '/NHP' is not allowed." // For whatever reason, accessing the site without a trailing slash causes this error. if (String.Compare(Request.Path, Request.ApplicationPath, StringComparison.InvariantCultureIgnoreCase) == 0 && !(Request.Path.EndsWith("/"))) Response.Redirect(Request.Path + "/"); } 

编辑:

另一件要检查的是Web.config中microsoft.identityModel中的federationAuthentication / wsFederation元素。 核实发行人和领域是否正确。

我正在使用WIF的表单身份validation。 表单auth模块将未经授权的请求redirect到正确的控制器,并将最初请求的URL存储在ReturnUrl参数中,所以我通过重写GetReturnUrlFromResponse方法来解决这个bug。

 /// <summary> /// Provides a workaround for a bug in the standard authentication module. /// </summary> /// <remarks> /// This class corrects WIF error ID3206 "A SignInResponse message may only /// redirect within the current web application..." /// WSFAM produces the error when the ReturnUrl is the root of the web application, /// but doesn't have a trailing slash. For instance, "/app" is considered incorrect /// by WSFAM whereas "/app/" is correct. /// </remarks> public class FixedWsFederationAuthenticationModule : System.IdentityModel.Services.WSFederationAuthenticationModule { /// <summary> /// Extracts the URL of the page that was originally requested from /// the sign-in response. /// </summary> /// <returns> /// The URL of the page that was originally requested by the client. /// This is the URL (at the relying party) to which the client should /// be redirected following successful sign-in. /// </returns> /// <param name="request"> /// The HTTP request that contains a form POST, which contains the /// WS-Federation sign-in response message. /// </param> protected override string GetReturnUrlFromResponse(HttpRequestBase request) { string returnUrl = base.GetReturnUrlFromResponse(request); // First Check if the request url doesn't end with a "/" if (!string.IsNullOrEmpty(returnUrl) && !returnUrl.EndsWith("/")) { // Compare if (return Url +"/") is equal to the Realm path, // so only root access is corrected. // /AppName plus "/" is equal to /AppName/ // This is to avoid MVC urls. if (string.Compare( returnUrl + "/", new Uri(Realm).LocalPath, StringComparison.InvariantCultureIgnoreCase) == 0) { // Add the trailing slash. returnUrl += "/"; } } return returnUrl; } } 

要使用这个类,你需要在web.config中注册它。 将此元素添加到system.webServer/modules部分,更改适当的部分:

 <add name="WSFederationAuthenticationModule" type="YOUR_NAMESPACE.FixedWsFederationAuthenticationModule, YOUR_ASSEMBLY" preCondition="managedHandler" /> 

当我将STS引用添加到我的Web应用程序时,我遇到了这个问题,默认情况下在dynamic端口上的虚拟服务器上运行。 我改变它运行它的IIS(如虚拟Web服务器,redirect到STS将不会发生,除非你运行它的IIS / IIS Express),并手动编辑web.config更改Microsoft.IdentityModelconfiguration下的受众URI。

当我看着FederationMetadata.xml时,它仍然指的是旧位置(带有dynamic端口)。 我刷新了我的STS参考,再次添加它,它的工作。