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