我正在使用MVC 3,elmah和nhibernate的遺留網站工作。 Elmah日誌字面上有成千上萬的「視圖」錯誤「或其主人未找到」錯誤。我認爲它正在掩蓋真正的錯誤。我無法弄清楚如何讓真正的錯誤被Elmah記錄下來。MVC 3,Elmah和視圖'錯誤'或其主人未找到
作爲嘗試調試的手段,我添加了 - 返回RedirectToAction(「noWhere」); - 強制執行錯誤。本地我得到一個.net屏幕,簡單地說,在處理請求時發生異常...「我得到YOSOD屏幕告訴我設置web.config客戶端節點。兩個都有客戶設置。
web配置有以下幾點:
<pages>
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
<httpModules>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
</httpModules>
<customErrors mode="On" defaultRedirect="~/Views/Shared/PageNotFound">
<error statusCode="404" redirect="~/Views/Shared/PageNotFound" />
<error statusCode="500" redirect="~/Views/Shared/PageNotFound" />
</customErrors>
在Global.asax有:
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new ElmahHandleErrorAttribute());
}
的ELMAH類有
public class ElmahHandleErrorAttribute : System.Web.Mvc.HandleErrorAttribute
{
public override void OnException(ExceptionContext context)
{
base.OnException(context);
var e = context.Exception;
if (!context.ExceptionHandled // if unhandled, will be logged anyhow
|| RaiseErrorSignal(e) // prefer signaling, if possible
|| IsFiltered(context)) // filtered?
return;
LogException(e);
}
和baseController類有:
protected ViewResult PageNotFound()
{
Response.StatusCode = (int)HttpStatusCode.NotFound;
return View("PageNotFound", PageViewModelBuilder.UpdateSiteProperties(new PageViewModel()));
}
protected ViewResult PageBadRequest()
{
Response.StatusCode = (int)HttpStatusCode.BadRequest;
return View("PageNotFound", PageViewModelBuilder.UpdateSiteProperties(new PageViewModel()));
}
上得到正確的錯誤登錄任何幫助,將不勝感激....
不幸的是,錯誤頁面是PageNotFound.cshtml – user1069733
是的,然後改變它。我編輯了我的答案。它解決了你的問題嗎?如果確實如此,請標記爲答案。 – StarCub
謝謝 - 但添加cshtml會導致httpexception被拋出,並且不會影響原始問題 – user1069733