首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Elmah错误过滤器

Elmah错误过滤器
EN

Stack Overflow用户
提问于 2012-04-12 23:58:02
回答 1查看 3.1K关注 0票数 3

我在web.config中设置了Elmah过滤器来停止某些错误消息的通知。但他们看起来还是挺过来了。可能的原因是什么?

代码语言:javascript
复制
 <httpModules>
  <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
  <add name="SecuritySwitch" type="SecuritySwitch.SecuritySwitchModule, SecuritySwitch" />
  <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
  <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
</httpModules>

<errorFilter>
  <test>
    <regex binding="Exception.Message" pattern="(?ix: \b This \b.+?\b is \b.+?\b an \b.+?\b invalid \b.+?\b webresource \b.+?\b request \b )" />
  </test>
  <test>
    <regex binding="Exception.Message" pattern="(?ix: \b Path \b.+?\b eurl.axd \b )" />
  </test>
  <test>
    <regex binding="Exception.Message" pattern="(?ix: \b potentially \b.+?\b dangerous \b.+?\b value \b.+?\b detected \b.+?\b client \b )" />
  </test>
</errorFilter>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-04-18 22:32:53

我相信你只能有一个测试元素。关键是从一个<or></or>元素开始,并在其中嵌套您的过滤器。这对我们来说当然是有效的。

代码语言:javascript
复制
<errorFilter>
    <test>
        <or>
            <!-- Don't email 404 errors -->
            <and>
                <equal binding="HttpStatusCode" value="404" type="Int32" />
                <regex binding="FilterSourceType.Name" pattern="mail" />
            </and>
            <!-- Don't log cancelled downloads -->
            <and>
                <equal binding="HttpStatusCode" value="500" type="Int32" />
                <equal binding="Context.Request.ServerVariables['URL']" value="/Download.aspx" type="String" />
                <or>
                    <regex binding="BaseException.Message" pattern="0x80070016" caseSensitive="false" />
                    <regex binding="BaseException.Message" pattern="0x800704CD" caseSensitive="false" />
                </or>
            </and>
            <!--Viewstate Corruption-->
            <or>
                <regex binding="Exception" type="System.Web.HttpException" pattern="System.FormatException: Invalid length for a Base-64 char array." caseSensitive="false" />
                <regex binding="Exception" type="System.Web.HttpException" pattern="System.FormatException: Invalid character in a Base-64 string." caseSensitive="false" />
            </or>
            <!-- IE8 Bug -->
            <and>
                <regex binding="Context.Request.ServerVariables['HTTP_USER_AGENT']" pattern="Trident\/4\.0" />
                <or>
                    <equal binding="Context.Request.ServerVariables['URL']" value="/ScriptResource.axd" type="String" />
                    <equal binding="Context.Request.ServerVariables['URL']" value="/WebResource.axd" type="String" />
                </or>
            </and>
        </or>
    </test>
</errorFilter>

更多信息请点击此处:

http://www.diaryofaninja.com/blog/2011/09/20/adding-filters-to-your-elmah-installation

票数 13
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10127302

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档