.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 属性的大小(字节)

相关推荐
张3蜂3 天前
java springboot2.0 api ;.netcore8 api ;python GunicornAPI ,哪种更强?请从多个维度,对比分析
java·python·.netcore
切糕师学AI4 天前
.NET Core Web 中的健康检查端点(Health Check Endpoint)
前端·kubernetes·.netcore
xdpcxq10294 天前
.NET Core 双数据库 PostgreSQL 与 SQLite 和平共处
数据库·postgresql·.netcore
csdn_aspnet8 天前
.Net Core — Cookie 身份验证
.netcore·cookie
csdn_aspnet8 天前
在 ASP.NET Core 中实现 Cookie 身份验证
后端·asp.net·.netcore·cookie
杨大枫10 天前
.Net Core 3.1|8.0 回调Minio WebHook事件进行数据同步
.netcore·minio
吹牛不交税10 天前
admin.net框架使用记录
vue·.netcore
weixin_4219947814 天前
更复杂的结构 - 类与对象
.net·.netcore
想起你的日子16 天前
ASP.NET Core EFCore之DB First
数据库·.netcore