提示
HTTP错误413.1 -请求实体太大
配置请求过滤模块拒绝超过请求内容长度的请求
为了解决这个问题,我做了以下操作:
增加了RequestFormLimits为int。MaxValue在我的控制器中像这样:
[RequestFormLimits(ValueLengthLimit = int.MaxValue, MultipartBodyLengthLimit = int.MaxValue)]
在startup.cs文件中添加了以下代码:
services.Configure<Microsoft.AspNetCore.Http.Features.FormOptions>(x =>
{
x.ValueLengthLimit = int.MaxValue;
x.MultipartBodyLengthLimit = int.MaxValue; // In case of multipart
});
在我的网页中添加了以下内容。配置文件
<system.webServer>
<security>
<requestFiltering>
<!-- 2 GB -->
<requestLimits maxAllowedContentLength="2147483648" />
</requestFiltering>
</security>
我试图上传1gb的文件,我得到一个错误说:
HTTP错误413.1 -请求实体太大
任何帮助都将非常感谢
如果你使用的是。net core 3.1或更低版本,试着在你的启动类中添加代码:
services.Configure<IISServerOptions>(options =>
{
options.MaxRequestBodySize = 2147483648;
});
官方文件:https://learn.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads?view=aspnetcore-3.1#iis-1