.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,再去试试
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
2022-10-27 Linux Supervisor使用
2020-10-27 c#面向对象说明