Asp.net MVC: how to catch 404 error?

in the old days, with asp.net, when I go to a non-existing page, the .net framework (or iis?) will throw 404, and I could attach the default page to this error on the Internet. config in the user error section.

but in asp.net mvc that doesn't seem to work? Does the mvc frame create some kind of invalid excpetion route saying that it cannot find any route for my uri or something like that?

+3
source share
1 answer

In the route registration, you can add a โ€œcatchingโ€ route after your other routes, so if the route does not match the current request, you can redirect it to a specific controller / action

From another answer in stack overflow:

routes.MapRoute("Error", "{*url}",
        new { controller = "Error", action = "404" }
    );
+4
source

Source: https://habr.com/ru/post/1741998/


All Articles