我有一个像这样的ActionFilterAttribute
public class DataModelAttribute : ActionFilterAttribute
{
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
...
throw filterContext.Exception; //StackTrace is fine (pointing to my controller)
}
}
我有一个像这样的全局错误过滤器:
public class OncHandleErrorAttribute : HandleErrorAttribute
{
public override void OnException(ExceptionContext context)
{
var ex = context.Exception; //Here StackTrace points to DataModelAttribute file
}
}
所以我丢失了原来的StackTrace ......我怎么能保留它呢?
答案 0 :(得分:1)
答案 1 :(得分:0)
在您的情况下,它看起来像这样:
public class HandleExceptionErrors : ActionFilterAttribute, IExceptionFilter
{
private Type _exceptionType;
public HandleExceptionErrors(Type exceptionType)
{
_exceptionType = exceptionType;
}
public void OnException(ExceptionContext filterContext)
{
if (filterContext.Exception.GetType() != _exceptionType) return;
filterContext.ExceptionHandled = true;
var data= filterContext.Exception +" , "+ filterContext.Exception.InnerException+" , "+filterContext.Exception.Message +" , "+filterContext.Exception.StackTrace;
}
}