3
我是ELMAH的新手,但我一直在使用MVC一段時間。在閱讀了關於這個主題的幾篇博文之後,我正在尋求處理404和未知錯誤頁面的ErrorController
,並製作一條默認路由,將所有未知路徑轉發到該控制器上的404動作。爲什麼我在ASP.NET MVC中使用ELMAH獲取重複的異常條目?
問題是,ELMAH記錄每個錯誤兩次;詳細記錄除標題中括號內的標識號外完全相同。
有沒有其他人遇到過這個問題?路由似乎工作很大,除了必須排除默認的{controller}/{action}/{id}
路由。
這裏是我的配置:
<configSections>
...
<sectionGroup name="elmah">
<section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
<section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
<section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
<section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
</sectionGroup>
...
</configSections>
<system.web>
...
<customErrors mode="On" defaultRedirect="~/error/unknown/">
<error statusCode="404" redirect="~/error/notfound/"/>
</customErrors>
...
<httpHandlers>
...
<add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah"/>
...
</httpHandlers>
...
<httpModules>
...
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
</httpModules>
</system.web>
<system.webserver>
<modules runAllManagedModulesForAllRequests="true">
...
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
</modules>
<handlers>
...
<add name="Elmah" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
</handlers>
</system.webserver>
<elmah>
<errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/errorlogpath" />
</elmah>
和路由代碼:
routes.MapRoute(
"ErrorDefault",
"error/{action}",
new { controller = "error", action = "unknown", id = "" }
);
routes.MapRoute(
"Default",
"{*url}",
new { controller = "error", action = "notfound", id = "" }
);
編輯:這裏的ErrorController爲好,只是我的測試目的:
/// <summary>
/// Handles error page routing
/// </summary>
public class ErrorController : Controller
{
/// <summary>
/// Action for unknown errors
/// </summary>
/// <returns></returns>
[AcceptVerbs(HttpVerbs.Get)]
public ViewResult Unknown()
{
Response.StatusCode = (int)HttpStatusCode.InternalServerError;
return View();
}
/// <summary>
/// Action for 404s
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
[AcceptVerbs(HttpVerbs.Get)]
public ViewResult NotFound(string path)
{
Response.StatusCode = (int)HttpStatusCode.NotFound;
return View();
}
}
你在哪裏實際記錄錯誤? – 2010-02-25 15:58:42
我正在使用將錯誤本地存儲在XML文件中的錯誤記錄方法。 – 2010-02-25 15:59:53
我的意思是如果ErrorController向Elmah發出錯誤信號,或者ErrorController只顯示一個通用錯誤頁面,並在其他地方發送信號。 – 2010-02-25 16:05:36