Используйте стандартные страницы ошибок ASP.NET (активируйте в web.config):
<customErrors mode="On|RemoteOnly" defaultRedirect="/error/problem">
<error statusCode="404" redirect="/error/notfound"/>
<error statusCode="500" redirect="/error/problem"/>
</customErrors>
И / или создайте контроллер обработки ошибок и используйте его по универсальному маршруту:
ErrorController.cs:
public class ErrorController : Controller
{
public ActionResult NotFound(string aspxerrorpath)
{
// probably you'd like to log the missing url. "aspxerrorpath" is automatically added to the query string when using standard ASP.NET custom errors
// _logger.Log(aspxerrorpath);
return View();
}
}
global.asax:
// This route catches all urls that do not match any of the previous routes.
// So if you registered the standard routes, somthing like "/foo/bar/baz" will
// match the "{controller}/{action}/{id}" route, even if no FooController exists
routes.MapRoute(
"Catchall",
"{*catchall}",
new { controller = "Error", action = "NotFound" }
);