ASP.NET MVC:将任何错误请求路由到我的自定义页面

时间:2011-05-12 07:40:56

标签: asp.net-mvc asp.net-mvc-routing

在ASP.NET MVC中,我需要将任何错误请求路由到我的自定义页面,我可以使用这种方式吗?

routes.MapRoute(
"Default", // Route name
"{*pathInfo}", 
new { controller = "Home", action = "NotFound" } 
);

并且,有没有更好的方法来实现它?

2 个答案:

答案 0 :(得分:0)

在global.asax中:

  public static void RegisterGlobalFilters(GlobalFilterCollection filters)
  {
        filters.Add(new HandleErrorAttribute() { View = "YourView" });
  }

答案 1 :(得分:0)

相关问题