【发布时间】:2014-12-05 02:58:45
【问题描述】:
像许多其他在 .NET 中处理 WIF 的人一样,我遇到了常见的错误:
ID3206:SignInResponse 消息只能在当前 网络应用程序。
我编写了一个自定义身份验证模块,我按照Error - A SignInResponse message may only redirect within the current web application - MVC 2.0 application 中的建议覆盖了 RedirectToIdentityProvider。
建议的代码示例没有考虑到请求 URL 可能包含参数,即它只会在完整 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 文件中的 realm 和 AudienceUri 以及 AD FS 2.0 端的标识符设置为请求 URL 的子集以外的值,只要该值是有效的 URI。例如,“http://corp.com”的虚假值就足够了。但是,使用这样的值意味着请求 URL 不会被 RedirectToIdentityProvider 覆盖处理。
我的问题是:
在 MVC 应用程序中让领域成为请求 URL 的子集的原因是什么?更重要的是,非 MVC 应用程序是否有同样的要求?
我可以不忽略领域并确保 URL 在末尾(如果没有参数的情况下)或参数列表之前包含斜杠吗?
【问题讨论】:
标签: asp.net vb.net wif adfs ws-federation