.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 @   qingjiawen  阅读(199)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
历史上的今天:
2022-10-27 Linux Supervisor使用
2020-10-27 c#面向对象说明
点击右上角即可分享
微信分享提示