0

我在 MVC 3 应用程序中创建了自定义异常处理程序,不幸的是,如果抛出异常,它永远不会被命中。我错过了什么吗?

自定义异常过滤器

public class ExceptionFilter : IExceptionFilter
{
        public void OnException(ExceptionContext filterContext)
        {
         //Never executed
        }
} 

在 Global.asax.cx 中注册过滤器

    public static void RegisterGlobalFilters(GlobalFilterCollection filters)
    {
        filters.Add(new ExceptionFilter()); //must be before HandleErrorAttribute
        filters.Add(new HandleErrorAttribute());
    }

网页配置

<customErrors mode="RemoteOnly" defaultRedirect="/error/default">
  <error statusCode="404" redirect="/error/pagenotfound" />
</customErrors>
4

1 回答 1

0

If you are testing by navigating to a missing page, what really happens is it tries to resolve the controller and you get an unhandled exception that throws a 500. Add a and you should be able to trap the other errors as well.

于 2012-09-25T18:50:54.713 回答