.net core 上传文件大小限制

微软官网文档中给的解释是.net core 默认上传文件大小限制是30M,所以即便你项目里没有限制,这里也有个默认限制。

官网链接地址

总结了一下解决办法:

1.首先项目里添加一个web.config自定义配置文件

在配置文件中加上这段配置

<!--//上传文件大小限制IIS设置 256M -->

<system.webServer>

<security>

<requestFiltering>

<requestLimits maxAllowedContentLength="268435456" />

</requestFiltering>

</security>

</system.webServer>

2.在Startup的ConfigureServices中添加代码段 //上传文件大小限制Kestrel设置

services.Configure<KestrelServerOptions>(options =>

{

// Set the limit to 256 MB

options.Limits.MaxRequestBodySize = 268435456;

});

//上传文件大小限制IIS设置

services.Configure<IISServerOptions>(options =>

{

options.MaxRequestBodySize = long.Parse(Configuration.GetSection("Kestrel").Value);

});

services.Configure<FormOptions>(x => x.MultipartBodyLengthLimit = 268435456);

3、打开 "管理" > "配置编辑器"

打开 "system.webServer/security/requestFiltering" 目录节点,并编辑 maxAllowedContentLength 属性的大小(字节)

相关推荐
dephixf2 天前
工业级部署指南:在西门子IOT2050(Debian 12)上搭建.NET 9.0环境与应用部署
物联网·.netcore·智能制造·边缘网关·西门子·iot 2050
睡前要喝豆奶粉2 天前
在.NET Core Web Api中使用JWT并配置UserContext获取用户信息
前端·.netcore
睡前要喝豆奶粉2 天前
在.NET Core Web Api中使用阿里云OSS
阿里云·c#·.netcore
周杰伦fans2 天前
.NET Core WebAPI 中 HTTP 请求方法详解:从新手到精通
网络协议·http·.netcore
睡前要喝豆奶粉4 天前
.NET Core Web API开发需引入的三个基本依赖配置说明
oracle·c#·.netcore
睡前要喝豆奶粉4 天前
.NET Core Web API中数据库相关配置
数据库·c#·.netcore
Archy_Wang_15 天前
Hangfire 入门与实战:在 .NET Core 中实现可靠后台任务处理
c#·.netcore
睡前要喝豆奶粉5 天前
在.NET Core Web Api中使用redis
redis·c#·.netcore
睡前要喝豆奶粉6 天前
多表分页联查——EF Core方式和Dapper方式
c#·.netcore
csdn_aspnet7 天前
.NETCore、.NET 7 和 RabbitMQ 的发布-订阅模式
rabbitmq·.netcore·.net7.