I have asp.net mvc RouteConfig as below, it's default one
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Home", id = UrlParameter.Optional }
);
}
In the web.config I have enabled the customerrors as below
Web.config
<customErrors mode="On" defaultRedirect="/Error/Error">
<error statusCode="404" redirect="/Error/NotFound" />
<error statusCode="500" redirect="/Error/Error" />
</customErrors>
Error Controller
public class ErrorController : Controller
{
public ActionResult Error()
{
if (!string.IsNullOrEmpty(Request.QueryString["aspxerrorpath"]))
{
return RedirectToAction("Error");
}
return View();
}
public ActionResult NotFound()
{
if (!string.IsNullOrEmpty(Request.QueryString["aspxerrorpath"]))
{
return RedirectToAction("Home", "Home");
}
return View();
}
}
When I hit the URL https://localhost:44351/a/a/a getting 404 and it's coming to Error controller, NotFound action from there it's redirecting to "Home" controller and "Home" action.
But when I hit the URL with more slashes in deep like https://localhost:44351/a/a/a/a getting default HTTP Error 404.0 - Not Found It's not routing to Error Controller, NotFound Action.
How to handle any level deep path to handle the custom 404?