Asp.net mvc 为什么IIS会绕过OneException错误处理
我的所有控制器都继承自Asp.net mvc 为什么IIS会绕过OneException错误处理,asp.net-mvc,iis,Asp.net Mvc,Iis,我的所有控制器都继承自BaseController,其中包括以下方法以支持错误日志记录和适当的重定向: protected override void OnException(ExceptionContext filterContext) { if (filterContext.ExceptionHandled) { return; } LogException(filterContext.Exception); if (filterC
BaseController
,其中包括以下方法以支持错误日志记录和适当的重定向:
protected override void OnException(ExceptionContext filterContext)
{
if (filterContext.ExceptionHandled)
{
return;
}
LogException(filterContext.Exception);
if (filterContext.Exception is PermissionException)
{
filterContext.Result = RedirectToAction("NotAuthorized", "Home");
filterContext.ExceptionHandled = true;
}
else
{
#if !DEBUG
filterContext.Result = RedirectToAction("Error", "Home");
filterContext.ExceptionHandled = true;
#endif
}
}
但是,IIS从未到达行
LogException
。如何配置IIS以允许该方法以与开发环境中相同的方式进行处理?我还可以使用其他方法在数据库中记录错误。ExceptionHandled是一个可以更改的值。您正在重写,该值作为true输入。您需要确定是否要处理它。异常已被处理,这就是logException未被命中的原因。我不确定,但您是否可以使用ELMAH?如果是,那么是什么导致部署的IIS上的ExceptionHandled
为true,而在开发环境中为false?可能是您注册了全局筛选器,或者在某个地方有一个属性,例如HandleError,它首先处理错误。