这个问题折腾我两天,正常的post和get提交没问题,一旦表单上传文件就会异常,网上资料基本都是在 Startup.cs->ConfigureServices最底部配置,或者没有说明配置位置,我的是配置在ConfigureServices的最顶部,才解决此问题,以下int.MaxValue根据需要自己调整。
//IIS上配置文件上传上限 发布后修改web.config或IIS设置
services.Configure<IISServerOptions>(options =>
{
options.MaxRequestBodySize = int.MaxValue;
});
services.Configure<Microsoft.AspNetCore.Http.Features.FormOptions>(x =>
{
x.ValueLengthLimit = int.MaxValue;
x.ValueCountLimit = int.MaxValue;
x.MultipartBodyLengthLimit = long.MaxValue;
x.MultipartBoundaryLengthLimit = int.MaxValue;
x.BufferBodyLengthLimit = long.MaxValue;
x.BufferBody = true;
x.MemoryBufferThreshold = int.MaxValue;
x.KeyLengthLimit = int.MaxValue;
x.MultipartHeadersLengthLimit = int.MaxValue;
x.MultipartHeadersCountLimit = int.MaxValue;
});