Web上传文件请求报错超过了最大请求长度

134
补充展位 Pages_Weblog_Get#0
文章摘要
此内容由人工摘要内容,并由AI根据文章内容进行润色
暂无内容

开发过程中遇到"System.Web.HttpException: 超过了最大请求长度。"的问题

如下面图图片所示,IIS默认请求长度4M,当请求长度大于这个数值限制的时候就会报错,

Web上传文件请求报错超过了最大请求长度

下面是解决方案.

修改:在web.config 中修改<system.web></system.web>节点中的 maxRequestLength,表示最大请求长度,单位是kb,系统默认的是4M限制 超出就会拒绝接受 该限制可用于防止因用户将大量文件传递到该服务器而导致的拒绝服务攻击。

<system.web>
         <!--最大请求长度,单位为kb-->
         <httpRuntime maxRequestLength="20480"  />
</system.web>`

修改在web.config中修改 <system.webServer></system.webServer>节点中的 maxAllowedContentLength 表示附件大小上限,单位是字节,默认约30M?

 <system.webServer>
       <!--允许上传文件长度,单位字节-->
       <security>
          <requestFiltering>
           <requestLimits maxAllowedContentLength="20971520"/>
         </requestFiltering>
       </security>
</system.webServer>

maxRequestLength与maxAllowedContentLength的区别:

  1. maxRequestLength 表示请求长度,
  2. maxAllowedContentLength 表示上传文件的大小;
  3. maxRequestLength 单位kb,
  4. maxAllowedContentLength? 单位字节;
  5. maxRequestLength 默认值4M,
  6. maxAllowedContentLength 默认值30000000B,约30M;
  7. 最大值都为2G 是这两者的共同点
补充展位
Pages_Weblog_Get#2e766efc-8a20-4917-86d2-bd95625e04ed
补充展位 Pages_Weblog_Get#1
补充展位 Pages_Weblog_Get#2
专题推荐
暂无内容
补充展位 Pages_Weblog_Get#3