2010-12-19 63 views
3

我的網站上asp.net MVC2運行,我使用ELMAH的錯誤捕獲,不是的HandleError attibuteasp.net的MVC 2周的customErrors IIS 7.5中不工作

如果我瀏覽到像 不存在的頁面的 'http://本地主機:8095 /家庭/城市/ 1/MTL/KO' 我得到了IIS錯誤404頁

在web.config中我已經配置我的自定義錯誤

我甚至試圖在global.asax application_error中設置代碼,它並沒有被困在那裏

爲什麼我會得到IIS 404錯誤頁面?

現在我想到了它,我想記錄404錯誤,我將在哪裏將這些陷阱在asp.net mvc中?

感謝

回答

0

我知道這是一個老問題,但認爲我的回答是:

ELMAH有可以應用過濾: http://code.google.com/p/elmah/wiki/ErrorFiltering

一旦啓用了錯誤過濾,你需要修改Gloabal.asax.cs來過濾錯誤:

public static void RegisterRoutes(RouteCollection routes) 
{    
    routes.IgnoreRoute("elmah.axd"); //Add this line to the register routes. 
} 

//ELMAH Filtering 
protected void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e) 
{ 
    FilterError404(e); 
} 

protected void ErrorMail_Filtering(object sender, ExceptionFilterEventArgs e) 
{ 
    FilterError404(e); 
} 

//Dimiss 404 errors for ELMAH 
private void FilterError404(ExceptionFilterEventArgs e) 
{ 
    if (e.Exception.GetBaseException() is HttpException) 
    { 
     HttpException ex = (HttpException)e.Exception.GetBaseException(); 

     if (ex.GetHttpCode() == 404) 
     { 
      e.Dismiss(); 
     } 
    } 
} 

但坦率地說,我喜歡記錄一切包括404錯誤。這讓我更好地瞭解用戶如何嘗試進入或發現新功能以支持需要。

其他資源: http://joel.net/logging-errors-with-elmah-in-asp.net-mvc-3--part-3--filtering http://ivanz.com/2011/05/08/asp-net-mvc-magical-error-logging-with-elmah/