我有一个在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.
I have even looked at the ASP.NET source code to verify that the warning only prints if you're trying to set the limit higher than the IIS settings ([1], [2]).
What am I doing wrong?
If it's relevant, I am publishing to IIS using Azure Pipelines. My repo does not contain a web.config
, but for good measure I tried with the following web.config
without luck:
<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中存在多个错误。此外,该限制必须在两个地方设置。请参阅此问题和链接的问题。综上所述:
web.config
值设置system.webServer.security.requestFiltering.maxAllowedContentLength
为Int32.MaxValue
IISServerOptions.MaxRequestBodySize
为Int32.MaxValue
这样就消除了警告(当然,将请求限制为〜2GB)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句