ASP.NET中maxRequestLength和maxAllowedContentLength的区别

maxRequestLength表示ASP支持的最大请求大小,而maxAllowedContentLength指定IIS支持的请求中内容的最大长度。因此,要上传大文件,我们需要同时设置这两个参数:较小的那个“优先”,即最终支持上传的文件的大小根据maxRequestLength和maxAllowedContentLength中的较小值而定。
如果文件长度小于maxAllowedContentLength但大于maxRequestLength,用户将获得标准(ASPX)错误页面。相反,用户会得到IIS错误页面。

HTTP Error 404.13 - Not Found

The request filtering module is configured to deny a request that exceeds the request content length.

需要在web.config中配置如下:

<system.web>

<httpRuntime requestValidationMode="2.0" maxRequestLength="3072" ></httpRuntime>

<!--单位:KB 3072=3MB 默认是4MB,最大支持2GB-->

</system.web>

<system.webServer>

<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483648" />
<!--单位:字节B 2147483648=2 GB 默认是4MB,最大支持2GB-->
</requestFiltering>
</security>

</system.webServer>

 

最后,需要注意的是,maxRequestLength的单位是KB,而maxAllowedContentLength的单位是字节,既然是请求,那么指的不仅仅是上传文件,只要是用户发送的请求,都可以通过上面的配置限制,比如Ajax请求服务器接口,参数内容超过了设置的最大长度就会请求失败

 

Stack Overflow 上的问答:asp.net - How to set the maxAllowedContentLength to 500MB while running on IIS7? - Stack Overflow
————————————————
版权声明:本文为CSDN博主「Tanjia_kiki」的原创文章
原文链接:https://blog.csdn.net/qq_23663693/article/details/89920039

posted @ 2022-10-06 11:46  百年俊少  阅读(126)  评论(0编辑  收藏  举报