How do I redirect a user to a custom 404 page in ASP.NET MVC instead of throwing an exception?

前端 未结 3 511
Happy的楠姐
Happy的楠姐 2020-12-06 05:04

I want to be able to capture the exception that is thrown when a user requests a non-existent controller and re-direct it to a 404 page. How can I do this?

For examp

相关标签:
3条回答
  • 2020-12-06 05:24

    Take a look at this page for routing your 404-errors to a specified page.

    0 讨论(0)
  • 2020-12-06 05:26

    Found this on the same site - Strategies for Resource based 404s

    0 讨论(0)
  • 2020-12-06 05:30

    Just use a route:

    // We couldn't find a route to handle the request.  Show the 404 page.
    routes.MapRoute("Error", "{*url}",
        new { controller = "Error", action = "404" }
    );
    

    Since this will be a global handler, put it all the way at the bottom under the Default route.

    0 讨论(0)
提交回复
热议问题