停止 IIS 解码 URL 中的 %2f

Ent*_*ith 5 iis kestrel-http-server asp.net-core

我的应用程序中有一个 API 端点,它接受一个字符串作为 URL 参数,该参数可能包含/编码为%2f.

例如, GET http://localhost:5000/api/foo/some%2fstring

控制器操作在其编码状态 ( some%2fstring) 中接收此参数,并能够在其认为合适的情况下进行处理。

但是,一旦部署到 IIS,这就会中断。IIS 似乎在将 URL 传递给 Kestrel 之前对其进行解码。日志显示如下:

info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
      Request starting HTTP/1.1 GET http://example.com/api/foo/some/string application/json 
Run Code Online (Sandbox Code Playgroud)

显然,该模式与路由和请求 404s 不匹配。

在将 URL 发送到 Kestrel 之前,如何防止 IIS 对其进行操作?