我花了很多时间试图找出一个解决方法,这无法使用,所以我想我会看到,如果有人在这里有一个想法。
我使用Elmah in my ASP.NET MVC3 application.我使用完全相同的代码从上一个链接中接受的答案。
我也有这个代码在我的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