我收到這個錯誤說
HTTP 錯誤 413.1 - Request Entity Too Large
請求過濾模塊配置為拒絕超過請求內容長度的請求
為了解決這個問題,我做了以下事情:
在我的控制器中將 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
});
在我的 web.config 檔案中添加了以下內容
<system.webServer>
<security>
<requestFiltering>
<!-- 2 GB -->
<requestLimits maxAllowedContentLength="2147483648" />
</requestFiltering>
</security>
我嘗試上傳 1 GB 檔案,但收到一條錯誤訊息:
HTTP 錯誤 413.1 - 請求物體太大
任何幫助將不勝感激
uj5u.com熱心網友回復:
如果您使用的是 .net core 3.1 或更低版本,請嘗試在您的啟動類中添加代碼:
services.Configure<IISServerOptions>(options =>
{
options.MaxRequestBodySize = 2147483648;
});
官方檔案:https ://docs.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads?view=aspnetcore-3.1#iis-1
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/466831.html
上一篇:如何在機器人框架中呼叫類方法?
下一篇:在WebSocket聊天中廣播
