我正在尝试配置ELMAH来过滤404错误,并在我的Web.config文件中遇到了XML提供的过滤规则的问题。我遵循教程here和here,并在我的<test><or>...
声明下添加了<is-type binding="BaseException" type="System.IO.FileNotFoundException" />
声明,但完全失败。ELMAH - 过滤404错误
当我测试了它在当地我在Global.asax的void ErrorLog_Filtering() {}
坚持一个断点,发现,获取ASP.NET为404打响了System.Web.HttpException
似乎并不具备的System.IO.FileNotFound
基本类型,而是简直就是System.Web.HttpException
。我通过在事件处理程序中调用e.Exception.GetBaseException().GetType()
来测试此操作。
接下来,我决定尝试一个<regex binding="BaseException.Message" pattern="The file '/[^']+' does not exist" />
,希望任何匹配模式“The file'/foo.ext'的模式不存在的异常消息”都会被过滤掉,但这也没有任何效果。作为最后的手段,我尝试了<is-type binding="BaseException" type="System.Exception" />
,甚至完全被忽视。
我倾向于认为ELMAH存在配置错误,但我看不到任何错误。我错过了明显的东西吗?
下面是从我的web.config相关的东西:
<configuration>
<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>
<elmah>
<errorFilter>
<test>
<or>
<equal binding="HttpStatusCode" value="404" type="Int32" />
<regex binding="BaseException.Message" pattern="The file '/[^']+' does not exist" />
</or>
</test>
</errorFilter>
<errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/App_Data/logs/elmah" />
</elmah>
<system.web>
<httpModules>
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah"/>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
</httpModules>
</system.web>
<system.webServer>
<modules>
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah"/>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
</modules>
</system.webServer>
</configuration>
是第二个链接抛出一个404哦...反讽 – Baldy 2013-06-14 09:17:20
@Baldy不幸的是,这是一个新的发展。你可以参考我的配置示例,了解你需要什么。 – 2013-06-19 17:20:28
它的好纳森,这个话题很有帮助。我只是觉得有趣的是,这个话题是关于404s的,并且页面上的一个链接导致了404 :) – Baldy 2013-06-20 08:15:50