我有一个在 IIS 上运行的 ASP.NET Core Web API。在一次操作中,我设置了IHttpMaxRequestBodySizeFeature.MaxRequestBodySize
至 262144000
.我已经使用 IIS 配置编辑器
ApplicationHost.config
为我的网站设置 system.webServer/security/requestFiltering/requestLimits/maxAllowedContentLength
至 4294967295
ApplicationHost.config
为我的网站设置 system.webServer/serverRuntime/maxRequestEntityAllowed
至 4294967295
Root Web.config
为我的网站设置 system.web/httpRuntime/maxRequestLength
至 2147483647
这些是我在选择
Web.config
时也看到的值在 IIS 配置编辑器中。该站点位于另一个充当反向代理的 IIS 站点之后。我在那里做了同样的改变。
我可以上传大于默认 ~30MB 限制的文件,但是每当我设置
IHttpMaxRequestBodySizeFeature.MaxRequestBodySize
时,我始终收到以下警告到一个很大的值:Increasing the MaxRequestBodySize conflicts with the max value for IIS limit maxAllowedContentLength. HTTP requests that have a content-length greater than maxAllowedContentLength will still be rejected by IIS. You can disable the limit by either removing or setting the maxAllowedContentLength value to a higher limit.
我什至查看了 ASP.NET 源代码,以验证仅在您尝试将限制设置为高于 IIS 设置( [1] 、 [2] )时才会打印警告。
我究竟做错了什么?
如果相关,我将使用 Azure Pipelines 发布到 IIS。我的 repo 不包含
web.config
,但为了更好的衡量,我尝试了以下 web.config
没有运气:<configuration>
<system.web>
<httpRuntime maxRequestLength="2147483647" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="4294967295" />
</requestFiltering>
</security>
</system.webServer>
</configuration>
最佳答案
事实证明,当将限制设置为高于 Int32.MaxValue 的值时,ASP.NET Core 中存在几个错误。此外,必须在两个地方设置限制。见 this issue和相关问题。总之:
web.config
值(value) system.webServer.security.requestFiltering.maxAllowedContentLength
至 Int32.MaxValue
IISServerOptions.MaxRequestBodySize
至 Int32.MaxValue
这消除了警告(当然也将请求限制为 ~2GB)。
关于asp.net-core - 如何在具有 maxAllowedContentLength 的 IIS 上的 ASP.NET Core 中使用 MaxRequestBodySize?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63172966/