我花了很多时间试图为这一个解决办法弄清楚无济于事,所以我想我会看看是否有人在这里有一个想法。
我用我的ASP.NET MVC3应用ELMAH 。 我使用的是从以前的链接接受的答案完全相同的代码。
我也有我的Global.asax这段代码用于显示与正确的HTTP响应错误页面:
/// <summary>
/// The customErrors functionality provided by ASP.NET results in HTTP 302 redirects occurring which doesn't accurately reflect what the real HTTP code of the response was.
/// This method can be used to handle specific HTTP codes without an intermediate redirect.
/// </summary>
protected void Application_Error() {
var exception = Server.GetLastError();
var httpException = exception as HttpException;
Response.Clear();
Server.ClearError();
var routeData = new RouteData();
routeData.Values["controller"] = "Error";
routeData.Values["action"] = "Error500";
Response.StatusCode = 500;
if (httpException != null) {
Response.StatusCode = httpException.GetHttpCode();
Response.TrySkipIisCustomErrors = true;
switch (Response.StatusCode) {
case 403:
routeData.Values["action"] = "Error403";
break;
case 404:
routeData.Values["action"] = "Error404";
routeData.Values["message"] = httpException.Message;
break;
case 500:
routeData.Values["action"] = "Error500";
break;
}
}
IController errorsController = new ErrorController();
var rc = new RequestContext(new HttpContextWrapper(Context), routeData);
errorsController.Execute(rc);
}
当我不是我的(本地)开发机器上发生的问题(最初让我觉得这是的customErrors相关)。 当一个异常被抛出,ELMAH处理错误,并正确记录它。 我也结束了正确的错误页面上。 然而,正确的错误页面上结束之前,我可以看到被记录的另一个中间例外:
The view 'Error' or its master was not found or no view engine supports the searched locations. The following locations were searched: ~/Views/Articles/Error.aspx ~/Views/Articles/Error.ascx ~/Views/Shared/Error.aspx ~/Views/Shared/Error.ascx ~/Views/Articles/Error.cshtml ~/Views/Articles/Error.vbhtml ~/Views/Shared/Error.cshtml ~/Views/Shared/Error.vbhtml
ASP.NET试图加载起来,即使我想处理它默认的错误页面。 有没有人对如何防止这种情况的任何想法?