I am using ASP.net Core 2.0 with MVC. I have a controller action that I want to limit the request size to 1MB. I added the RequestSizeLimit
attribute like so:
[HttpPost]
[Authorize]
[RequestSizeLimit(1_000_000)]
public async Task<List<ResourceUploadResult>> Upload([FromBody]List<Resource> updatedList){
//....
}
When the upload is < 1MB, it works as expected. When it is > 1MB I expected the server to return a status of 413, but instead, the updatedList
parameter is null and the action executes normally, running into a NullReferenceException
when it tries to iterate the list.
Is there a way to tell Kestrel to return 413 when the size limit is reached?
Probably not the best, but it will work in the mean time.
if(updatedList == null)
return StatusCode(413, "Payload to big") ;
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