我想將一個大小約為 80Mb 的檔案上傳到我的控制器:
[HttpPost("UploadJar")]
[RequestFormLimits(MultipartBodyLengthLimit = 104857600)]
public ActionResult UploadJar([FromForm]IFormFile file)
{
if (file is not { Length: > 0 })
{
return BadRequest();
}
var filePath = $"{Path.GetTempPath()}{Guid.NewGuid()}.jar";
using (var stream = System.IO.File.Create(filePath))
{
file.CopyTo(stream);
}
if (ValidateJarFile(filePath) == false)
{
System.IO.File.Delete(filePath);
return BadRequest();
}
HttpContext.Session.SetString("jarFileTempPath", filePath);
return Ok();
}
我的Startup課程包含以下配置:
services.Configure<IISServerOptions>(options =>
{
options.MaxRequestBodySize = 120000000; // 120Mb
});
services.Configure<KestrelServerOptions>(options =>
{
options.Limits.MaxRequestBodySize = 120000000; // 120Mb, if don't set default value is: 30 MB
});
我與 Jetbrains Rider 一起使用的組態檔是:
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"ASP.NETCoreWebApplication": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
當我使用組態檔時ASP.NETCoreWebApplication,一切都很好,但如果我使用組態檔IIS Express,上傳檔案時會出現 413(檔案太大)錯誤。
誰能給我解釋一下?
uj5u.com熱心網友回復:
在網路中。在 System.WebServer 下配置你需要把它。
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="524288000"/>
</requestFiltering>
</security>
請參閱以下鏈接 - IIS Express 的默認限制 <limits>
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/490591.html
