許多其他人一樣具有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在最後(如果沒有參數)或參數列表之前包含一個斜線?