1. 首页>
  2. 技术文章>
  3. ASP.NET中maxRequestLength和maxAllowedContentLength的区别;上传大文件设置IIS7文件上传的最大大小

ASP.NET中maxRequestLength和maxAllowedContentLength的区别;上传大文件设置IIS7文件上传的最大大小

4/24/22 7:19:37 PM 浏览 967 评论 0

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>


网友讨论