I'm trying to upload a 100MB film to my ASP.NET Core application.
I've set this attribute on my action:
[RequestSizeLimit(1_000_000_000)]
And I also changed my Web.config
file to include:
<security>
<requestFiltering>
<!-- This will handle requests up to 700MB (CD700) -->
<requestLimits maxAllowedContentLength="737280000" />
</requestFiltering>
</security>
In other words, I've told IIS to allow files up to 700MBs and I've also told ASP.NET Core to allow files of near 1GB.
But I still get that error. And I can't find the answer. Any ideas?
P.S: Using these configurations, I could pass the 30MB default size. I can upload files of 50 or 70 Mega Bytes.
I think you just need: [DisableRequestSizeLimit]
below is a solution that worked for me to upload Zip files with additional form data to an API running .Net Core 3
// MultipartBodyLengthLimit was needed for zip files with form data.
// [DisableRequestSizeLimit] works for the KESTREL server, but not IIS server
// for IIS: webconfig... <requestLimits maxAllowedContentLength="102428800" />
[RequestFormLimits(ValueLengthLimit = int.MaxValue, MultipartBodyLengthLimit = int.MaxValue)]
[DisableRequestSizeLimit]
[Consumes("multipart/form-data")] // for Zip files with form data
[HttpPost("MyCustomRoute")]
public IActionResult UploadZippedFiles([FromForm] MyCustomFormObject formData)
{ }
NOTE: This is issue I faced when I migrated my application from asp.net core 2.1 to 3.0
To fix this in asp.net core 3.0 I have changed my program.cs to modify maximum request body size like below.
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args)
{
return WebHost.CreateDefaultBuilder(args)
.ConfigureKestrel((context, options) =>
{
options.Limits.MaxRequestBodySize = 737280000;
})
.UseStartup<Startup>();
}
}
}
I mean I have just added ConfigureKestrel
part and added an attribute above my action method [RequestSizeLimit(737280000)]
like below
[HttpPost]
[RequestSizeLimit(737280000)]
[Route("SomeRoute")]
public async Task<ViewResult> MyActionMethodAsync([FromForm]MyViewModel myViewModel)
{
//Some code
return View();
}
And my application started behaving correctly again without throwing BadHttpRequestException: Request body too large
reference: https://learn.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads?view=aspnetcore-3.0#kestrel-maximum-request-body-size
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With