2014-12-04 56 views
0

許多其他人一樣具有WIF在.NET處理我遇到了平時的錯誤:WSFederationAuthenticationModule:RedirectToIdentityProvider:域是否必須是請求URL的子集?

ID3206: A SignInResponse message may only redirect within the current web application.

我寫的,我推翻RedirectToIdentityProvider在Error - A SignInResponse message may only redirect within the current web application - MVC 2.0 application提出了一個自定義的驗證模塊。

建議的代碼示例未考慮到請求URL可能包含參數,即它只是簡單地將完整的URL添加尾部斜槓。最後,我擴大了代碼,你看到下面有什麼,但仍然使用的領域,以便決定是否要處理的網址:

Public Overrides Sub RedirectToIdentityProvider(ByVal uniqueId As String, ByVal returnUrl As String, ByVal persist As Boolean) 
    Dim absoluteUri As String = HttpContext.Current.Request.Url.AbsoluteUri 
    Dim ciAbsoluteUri As String = absoluteUri.ToLowerInvariant 

    Dim realm As String = MyBase.Realm 
    Dim ciRealm As String = realm.ToLowerInvariant 

    'If Realm ends with a trailing slash, the returnUrl should include a trailing slash in the same position. 
    'This trailing slash may or may not be the end of the returnUrl, depending on whether or not additional parameters have been provided. 
    If realm.EndsWith("/") Then 
     If Not ciAbsoluteUri.StartsWith(ciRealm) Then 
      Dim realmWithoutSlash As String = realm.Substring(0, realm.Length - 1) 
      Dim ciRealmWithoutSlash As String = realmWithoutSlash.ToLowerInvariant 
      If ciAbsoluteUri.StartsWith(ciRealmWithoutSlash) Then 
       'Realm ends with a slash and AbsoluteUri contains Realm but without a slash. 
       Dim absolutePath As String = HttpContext.Current.Request.Url.AbsolutePath 
       returnUrl = returnUrl.Replace(absolutePath, absolutePath & "/") 
      End If 
     End If 
    End If 

    MyBase.RedirectToIdentityProvider(uniqueId, returnUrl, persist) 

End Sub 

(這也可以寫成更爲緊湊,但是這是除了點。)

在原崗位的代碼包括以下注釋

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

這是完全可以設置在web.config文件的領域和audienceUri和比其它的東西在AD FS 2.0一側的標識符請求URL的子集爲lo ng,因爲該值是有效的URI。例如,「http://corp.com」的僞造值就足夠了。但是,使用這樣的值將意味着請求URL不會被RedirectToIdentityProvider覆蓋處理。

我的問題是:

什麼是有境界是在MVC應用程序,並請求URL的一個子集的原因 - 更重要的是 - 是有需要相同的非MVC應用程序的理由?

難道我不能忽略這個領域,並確保URL在最後(如果沒有參數)或參數列表之前包含一個斜線?

回答

2

只是一些基本知識:Realm是WIF語言,用於元數據中的EntityID。它應該是一個URI。這意味着它不一定是一個URL。幾乎所有的實現都非常寬容,並且接受EntityID中的任何字符串。
Returnurl在這種情況下表示瀏覽器在用戶通過身份驗證並且WIF已設置會話cookie之後所經過的url。它應該在應用程序內(爲什麼其他身份驗證)。如果你真的想要應用程序根目錄,那麼結尾的斜線確實是一個好主意(因爲cookiepath)。所以Realm的使用(在這種情況下)是一個錯誤。

相關問題