35

我有一个情况,我们有一个MVC 2应用程序(我有一个基本的MVC 2应用程序尝试这样做没有任何多余的东西,还是同样的问题) - 一个SignInResponse消息可能只有当前的网络应用程序中的重定向并使用adfs 2来验证我的用户。错误 - MVC 2.0应用程序

所以.. 现在我进入我的申请,得到了下面.. ID3206:一个SignInResponse消息只可在当前Web应用程序中重定向:“/ [应用]”是不允许的。 描述:执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪以获取有关该错误的更多信息以及源代码的位置。 异常详细信息:Microsoft.IdentityModel.Protocols.FederationException:ID3206:SignInResponse消息只能在当前Web应用程序内重定向:不允许使用'/ [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. 我对境界和audienceUris尾随斜线。
  2. 我已经添加了他对Application_BeginRequest的建议 - 然后我将代码复制到[开发域],因为那是证书所在的地方..然后它就陷入了一个无限循环。
  3. 我也检查了我的依赖方日内瓦服务器上。该标识符和端点(POST)都是https://开头[开发域]/[程序]/- 再次与结尾的斜线

我认为这是一个问题,因为它是一个MVC应用程序,我创建了大量声明感知网站,并在default.aspx页面上获得了我的声明等。我的想法是,涉及MVC应用程序的路由以某种方式发布它错误?

真的apprecaited作为即时通讯的任何帮助寻找在这个安静的,而现在无济于事..

Ĵ

+1

我有MVC4同样的问题。 – SGarratt 2012-11-28 10:44:13

回答

34

我一直在撕裂我的头发就这一个。我也有我的配置中指定的尾部斜线。事实证明,在我的情况下,导航到我的应用程序,像这样在浏览器中结尾的斜线:

http://localhost/myapp/

会的工作,而

http://localhost/myapp

不会。

如果我能挖掘出一些更多的原因是这样的话,我会添加上为什么发生这种情况更多一些背景。

+1

+1 - 这救我很有些无奈:) – VoodooChild 2012-05-10 18:03:48

+0

感谢,这救了我的 – Rahul 2014-03-19 23:35:02

2

当我向我的web应用程序添加STS引用时,出现了此问题,默认情况下,该应用程序在动态端口上的虚拟服务器上运行。我改变它运行它的IIS(如虚拟Web服务器,重定向到STS不会发生,除非你运行它的IIS/IIS Express),并手动编辑web.config更改Microsoft.IdentityModel配置下的受众URI。

当我在FederationMetadata.xml来看,它仍然指的是旧的位置(使用动态端口)。我再次添加它并且它工作,我刷新了我的STS参考。

10

此代码需要照顾的是(把它在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中的microsoft.identityModel的federationAuthentication/wsFederation元素。配置。验证发行人和领域是否正确。

+1

天用这种方法我结束了与IP-STS和RP上签到 – Vladislav 2014-08-05 11:20:14

+0

之间的一些奇怪的无尽重定向我想别的东西上,然后是怎么回事但我无法告诉你什么。 – 2014-08-05 13:17:45

+0

这对我们很有用,并且是最容易实现的。我们的情况是,我们在一个网站中有几个虚拟应用程序,因此每个虚拟应用程序都作为它自己的“文件夹”中的页面登录,上面解决了问题。 – 2016-05-11 20:38:03

16

我对WSFederationAuthenticationModule子类覆盖RedirectToIdentityProvider。在重定向到STS之前,这只会发生一次。你必须告诉config文件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); 
    } 
} 
+1

这在我的MVC4应用程序中修复了它,谢谢。 – SGarratt 2012-11-28 10:44:41

+4

这里是你的web.config的语法: ADH 2013-10-11 18:41:49

+0

有没有理由继承子类而不是放入'WSFederationAuthenticationModule_RedirectingToIdentityProvider'? 'RedirectingToIdentityProviderEventArgs'允许你根据我的情况改变'SignInRequestMessage'。 – 2014-09-23 00:54:33

5

我使用的是WIF Forms身份验证使用这个类FixedWSFederationAuthenticationModule代替defualt的。该窗体身份验证模块重定向未授权请求到正确的控制器和存储在ReturnUrl参数最初请求的URL,所以我的工作解决此bug通过覆盖GetReturnUrlFromResponse方法。

/// <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" />