.net 上传附件错误

 

错误

net::ERR_CONNECTION_ABORTED 

  • 导致这种错误的主要原因是上传的文件太大,服务器不能继续读取请求而过早中断链接

Failed to load resource: the server responded with a status of 413 ()

开发环境(IISExpress)

1073741824=1GB
根目录下创建 web.config 文件,内容如下
<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.webServer>
        <security>
            <requestFiltering> 
                <requestLimits maxAllowedContentLength="1073741824" />
            </requestFiltering>
        </security>
    </system.webServer>
</configuration>

生产环境

通常生产环境 IIS 自动项目添加了 web.config 文件,这时候只需要在 <configuration> 节点下添加下面内容即可:

<system.webServer>
    <security>
        <requestFiltering>
            <requestLimits maxAllowedContentLength="1073741824" />
        </requestFiltering>
    </security>
</system.webServer>

 对api方法中可以设置不限制大小,或者填入大小

 

nginx 上传限制 client_max_body_size

http {
    include       mime.types;
    default_type  application/octet-stream;
    client_max_body_size 1000m
}

 

前端项目vue axios

Uncaught (in promise) Error: timeout of 6000ms exceeded

 

Multipart body length limit 134217728 exceeded.

Post的body大概超过100多M会碰到这个错误

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();
    //解决Multipart body length limit 134217728 exceeded
    services.Configure(x =>
    {
        x.ValueLengthLimit = int.MaxValue;
        x.MultipartBodyLengthLimit = int.MaxValue; // In case of multipart
    });
}

 

IIS配置

httpRuntime 中 maxRequestLength就是设置你最大请求大小限制;
requestLimits 中 maxAllowedContentLength就是设置你上传文件的大小限制(请求中内容的最大长度);

maxRequestLength的单位是KB,而maxAllowedContentLength的单位是字节B

 <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> 

 

打开iis,选择配置编辑器(修改两处,system.webServer/security/requestFiltering;system.web/httpRuntime)

 

 可以发现,最大上传值被限制到了30m,于是再后面加两个0,使其达到3G,再去试试

 

posted @ 2023-10-27 11:42  qingjiawen  阅读(119)  评论(0编辑  收藏  举报