我正在尝试在 ASP.NET Web Forms (ASPX) 应用程序中实现 ITfoxtec SAML 2.0。
通常的 ASP.NET MVC 实现使用以下语句:
binding.ReadSamlResponse(Request.ToGenericHttpRequest(), saml2AuthnResponse);
但 MVC Request
在 Web 表单中不可用。
在 VB 中我尝试过如下代码
Dim request As New ITfoxtec.Identity.Saml2.Http.HttpRequest
request.Method = "GET"
request.Query = HttpContext.Current.Request.Form
binding.ReadSamlResponse(request, saml2AuthnResponse)
但这引发了异常:
Found invalid data while decoding.
at System.IO.Compression.InflaterZlib.Inflate(FlushCode flushCode)
at System.IO.Compression.InflaterZlib.ReadInflateOutput(Byte[] outputBuffer, Int32 offset, Int32 length, FlushCode flushCode, Int32& bytesRead)
at System.IO.Compression.InflaterZlib.Inflate(Byte[] bytes, Int32 offset, Int32 length)
at System.IO.Compression.DeflateStream.Read(Byte[] array, Int32 offset, Int32 count)
at System.IO.Stream.InternalCopyTo(Stream destination, Int32 bufferSize)
at System.IO.Stream.CopyTo(Stream destination)
at ITfoxtec.Identity.Saml2.Saml2RedirectBinding.DecompressResponse(String value)
at ITfoxtec.Identity.Saml2.Saml2RedirectBinding.Read(HttpRequest request, Saml2Request saml2RequestResponse, String messageName, Boolean validateXmlSignature, Boolean detectReplayedTokens)
at ITfoxtec.Identity.Saml2.Saml2Binding`1.ReadSamlResponse(HttpRequest request, Saml2Response saml2Response)
at [my code]
如何将 HttpContext.Current.Request
转换为 ITfoxtec.Identity.Saml2.Http.HttpRequest
?
希望得到帮助,
大卫。
最佳答案
谢谢安德斯。
我之所以出现这个问题,是因为我无意中将 binding
声明为 Saml2RedirectBinding
而不是 Saml2PostBinding
。更正此问题后,ASP.NET MVC C# 语句:
binding.ReadSamlResponse(Request.ToGenericHttpRequest(), saml2AuthnResponse);
对于 VB 中的 ASP.NET Web 窗体,需要如下所示:
Dim request As New ITfoxtec.Identity.Saml2.Http.HttpRequest With
{
.Method = HttpContext.Current.Request.HttpMethod,
.Form = HttpContext.Current.Request.Form,
.Query = New NameValueCollection,
.QueryString = ""
}
binding.ReadSamlResponse(request, saml2AuthnResponse)
以防其他人需要此解决方案。
大卫。
关于itfoxtec-identity-saml2 - ITfoxtec SAML 2.0 和 ASP.NET Web 表单 (ASPX) HttpRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70735069/