I want a low default MaxRequestBodySize, let's say 2MB. Then, endpoints dealing with user uploads would have this limit lifted to an arbitrary number via the RequestSizeLimit attribute, like so:
[RequestSizeLimit(Limit30Mb)]
[HttpPost, Route("mb30")]
public async Task<IActionResult> Mb30(List<IFormFile> files) => Ok(new { FileName = Request.Form.Files[0].FileName });
my ConfigureWebHostDefaults looks like this
.ConfigureWebHostDefaults(webHost =>
{
webHost.ConfigureKestrel(kestrelOptions =>
{
kestrelOptions.Limits.MaxRequestBodySize = RequestSizeLimits.Limit2Mb;
});
})
The attribute works fine during local development (using Kestrel without IIS), but the default isn't set when running in Azure.
I have a web.config that looks like this:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="4294967295" />
</requestFiltering>
</security>
</system.webServer>
to allow 4gigs into the app on Azure - this can be used to lower the "ceiling" for whole app and once lowered the MaxRequestBodySize does not take any effect.
here I found that when deployed to Azure with IIS it does uses Kestrel, so I would expect the kestrelOptions.Limits.MaxRequestBodySize would be working. But it is not.
Also I found UseIIS extension method which configures IISServerOptions inside which has MaxRequestBodySize so that might be it for the scenario with IIS, possibly?