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 @   百年俊少  阅读(442)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
点击右上角即可分享
微信分享提示