In my case, I am working on ASP.NET Core 5 project and I need to limit the maximum size for the entire form content to 2MB.
I have added the following attribute to my controller
[RequestFormLimits(ValueLengthLimit = 1024 * 1024 * 2)]
public class MyController : Controller
{
...
}
but the problem is that anytime a user tries to upload an image or any other form item that makes the entire content of the form to be more than 2MB, the application returns a 404 error.
I am looking for a way to rather display an error message when the entire content of the form exceeds 2MB.
I will appreciate any guide to handle this error gracefully instead of the 404 error it currently displays to users
Thank you