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

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.

Leave a Comment