2013-04-01 21 views
0

我正在使用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())); 
    } 

上得到正確的錯誤登錄任何幫助,將不勝感激....

回答

1

變化"~/Views/Shared/PageNotFound"在你的web.config "~/Views/Shared/PageNotFound.aspx」(或"~/Views/Shared/PageNotFound.chtml」),並確保你在你的Shared文件夾中有PageNotFound.aspx

+0

不幸的是,錯誤頁面是PageNotFound.cshtml – user1069733

+0

是的,然後改變它。我編輯了我的答案。它解決了你的問題嗎?如果確實如此,請標記爲答案。 – StarCub

+0

謝謝 - 但添加cshtml會導致httpexception被拋出,並且不會影響原始問題 – user1069733

相關問題