简体   繁体   中英

ExceptionFilter do not handle exceptions

I have created custom exception handler in MVC 3 app, unfortunately it is never hit if exception is thrown. Do I miss something?

Custom exception filter

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

Registering filter in Global.asax.cx

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

Web.config

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

如果要通过导航到缺少的页面进行测试,则实际发生的情况是它尝试解析控制器,并且您收到未处理的异常,该异常抛出500。添加a并且您也应该能够捕获其他错误。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM