IIS 8.5 400 错误请求 - 无效 URL

IIS 8.5 400 Bad Request - Invalid URL

我收到了 URL 这种类型的请求: https://xxx/test/%81

这导致 400 错误请求 - 无效 URL

我尝试在 web.config 中设置:

<httpRuntime requestValidationMode="2.0" relaxedUrlToFileSystemMapping="true" requestPathInvalidCharacters=""/>

但这并没有帮助。

我也尝试过使用自定义请求验证器:

<httpRuntime requestValidationType="MyNamespace.CustomRequestValidation"/>

但是 IIS returns 400 在使用自定义验证器之前。

我还能做些什么来让 IIS 接受这个 URL?

谢谢。

根据 https://www.iis.net/learn/troubleshoot/diagnosing-http-errors/troubleshooting-http-400-errors-in-iis HTTP 400 的根本问题是客户端向 IIS 发送了一个请求,该请求违反了 HTTP.sys 正在执行的一个或多个规则。

Http.sys Windows 的注册表设置在此处描述: https://support.microsoft.com/en-us/kb/820129

因此,在我的案例中,通过在 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\HTTP\Parameters 下创建以下 DWORD 值作为 IIS 机器解决了问题:

AllowRestrictedChars = 1
EnableNonUTF8 = 1

将这些更改应用到注册表后,必须重新启动 IIS 机器