我的基本 Controller 中有这个
protected override void OnException(ExceptionContext filterContext)
{
if (filterContext.ExceptionHandled)
{
return;
}
var logger = new Logger();
logger.LogError(filterContext.Exception, ControllerContext.RouteData.Values["controller"].ToString());
filterContext.Result = new ViewResult
{
ViewName = "~/Views/Shared/Error.cshtml",
ViewData = new ViewDataDictionary()
{
{"exception", filterContext.Exception}
}
};
filterContext.ExceptionHandled = true;
}
我肯定在
Views/Shared/Error.cshtml
但是,无论何时发生未处理的异常,我都会在日志中收到此错误
Path '/Views/Shared/Error.cshtml' was not found.
但是根据this article这应该工作...
这怎么可能?
最佳答案
我认为您不需要全名,因为它是默认页面。你试一试
filterContext.Result = new ViewResult
{
ViewName = "Error",
ViewData = new ViewDataDictionary()
{
{"exception", filterContext.Exception}
}
};
希望这对您有用!
关于c# - 找不到路径 '/Views/Shared/Error.cshtml',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50559511/