文件上传长度限制

解决方案:修改web.config文件

1、注意在mvc中有两个web.config文件,如下图,一个位于Views下,是用来控制view中的文件;还有一个在位于根目录下,对所有文件起作用。我们修改根目录下web.config

2、修改maxRequestLength:在web.config中我们修改<system.web></system.web>中的maxRequestLength,表示最大请求长度,单位是kb,默认4M

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

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

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

注意: 

maxRequestLength与maxAllowedContentLength的区别:

a、前者表示请求长度,后者表示上传文件的大小;

b、前者单位kb,后者单位字节;

c、前者默认值4M,后者默认值30000000B,约30M;

d、两者的最大值都为2G

原文地址:https://www.cnblogs.com/liandy0906/p/7374524.html