I'm new to ASP.NET MVC and in general; I endured the ASP.NET MVC application in ASP.NET MVC Core. In the former structure, I was able to handle HttpException for the following infamous error:
HTTP 404.13 error - not found
filtering module is configured to request rejection of the request that exceeds the request content length.
I know that I can increase the maximum allowable load length, which by default is 30 MB, but my goal - to introduce user friendly error page explaining what had just happened, and not to increase the limit.
In ASP.NET, I did it with the following code to my Global.asax:
private void Application_Error(object sender, EventArgs e) { var ex = Server.GetLastError(); var httpException = ex as HttpException ?? ex.InnerException as HttpException; if (httpException == null) return; if (httpException.WebEventCode == WebEventCodes.RuntimeErrorPostTooLarge) {
I can not find alternatives to this in Asp.Net Core after a few hours of research. I believe that I will need to connect an intermediate software in my method Startup.cs Configure to create a custom error page to handle exceptions HttpException and redirect, but I really lost this question.
I was able to successfully use the following middleware software for custom error pages for HTTP-errors, such as 404 - Not Found or 403 - Forbiden, using the following method in my configure:
app.UseStatusCodePagesWithReExecute("/Error/StatusCode{0}");
In addition to the controller:
public class ErrorController : Controller { public IActionResult StatusCode404() { return View(viewName: "CustomNotFound"); } public IActionResult StatusCode403() { return View("CustomForbiden"); } } ); public class ErrorController : Controller { public IActionResult StatusCode404() { return View(viewName: "CustomNotFound"); } public IActionResult StatusCode403() { return View("CustomForbiden"); } }
And appropriate representation. However, the error 404.13 (load is too large) will not be processed my current middleware. I believe that IIS is a mistake, because it is not processed by the web application.