【发布时间】:2015-10-18 00:09:56
【问题描述】:
在我的 ASP.NET MVC 项目中,我将 /errors/error.html 页面作为一般错误页面,并使用第二个 /errors/error404.aspx 处理 404 错误。
<customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="/errors/error.html">
<error statusCode="404" redirect="/errors/error404.aspx" />
</customErrors>
另外,我的Global.asax 文件中有一个通用处理程序,用于记录所有未捕获的异常以进行日志记录。
public void Application_Error(object sender, EventArgs e)
{
Exception ex = Server.GetLastError();
Common.Core.LogError(ex); // Saving exception details in the database
}
上述设置运行良好,但当我遇到一般错误(例如 500 错误)时,Application_Error 在下面记录此错误:
未找到视图“错误”或其主视图,或者没有视图引擎支持搜索到的位置。搜索了以下位置:
~/Views/app/Error.aspx
~/Views/app/Error.ascx
~/Views/Shared/Error.aspx
~/Views/Shared/Error.ascx
~/Views/app/Error.cshtml
~/Views/app/Error.vbhtml
~/Views/Shared/Error.cshtml
~/Views/Shared/Error.vbhtml
根本不记录来自实际错误的异常。
我怎样才能避免这个错误?
附:对于任何可能会问的人,我尝试将我的错误页面作为视图放在控制器中,但我也无法使用 redirectMode="ResponseRewrite" 选项使其工作。
【问题讨论】:
标签: asp.net asp.net-mvc error-handling web-config custom-error-pages