【问题标题】:ELMAH regex REMOTE_ADDR filter not workingELMAH 正则表达式 REMOTE_ADDR 过滤器不起作用
【发布时间】:2017-02-19 05:08:55
【问题描述】:

当已知进程访问我们网站上不存在的 URL 时,ELMAH 会生成如下异常:

System.Web.HttpException:路径“/manager/”的控制器不是 找到或没有实现 IController。

而从浏览器访问该不存在的 URL 会生成典型的 IIS 404。

找不到资源。说明:HTTP 404。你的资源 正在寻找(或其依赖项之一)可能已被删除, 名称已更改,或暂时不可用。请查阅 以下 URL 并确保其拼写正确。

请求的网址:/manager

我知道访问这些地址的过程是无害的,并且希望停止接收这些特定的电子邮件,这些电子邮件是从一系列 IP 地址生成的。这就是我在 web.config 中的内容,但 ELMAH 电子邮件仍然可以通过。

URL 过滤器似乎工作正常。

      <elmah>
        <security allowRemoteAccess="false" />
        <errorMail from="elmah@mydomain.com" to="elmahlog@mydomain.com" async="true" smtpServer="mail.mydomain.com" smtpPort="25" useSsl="false" />
        <errorFilter>
          <test>
            <and>
              <equal binding="HttpStatusCode" value="500" type="Int32" />
              <or>
                <!--TrustWave scans our website with intentional bad addresses-->
                <regex binding="Context.Request.ServerVariables['REMOTE_ADDR']" pattern="64.37.231.\d{1,3}" type="String" />

                <!--Google looking for Digital Asset Links - well known statements the website wants to make-->
              <regex binding="Context.Request.ServerVariables['URL']" pattern="/.well-known/assetlinks.json" type="String" />

                <!--Apple devices searching for universal links - app-site association. we dont have an app.-->
                <regex binding="Context.Request.ServerVariables['URL']" pattern="/.well-known/apple-app-site-association" type="String" />            
              </or>
            </and>
          </test>
        </errorFilter>
      </elmah>

【问题讨论】:

    标签: asp.net-mvc elmah elmah.mvc


    【解决方案1】:

    尽管 ELMAH 电子邮件看起来像是发生了 500 错误,但 web.config 确实需要 404 错误代码才能使过滤器正常工作。

    &lt;equal binding="HttpStatusCode" value="404" type="Int32" /&gt;

    而不是

    &lt;equal binding="HttpStatusCode" value="500" type="Int32" /&gt;

    【讨论】:

      猜你喜欢
      • 2016-03-18
      • 1970-01-01
      • 1970-01-01
      • 2017-12-27
      • 1970-01-01
      • 2012-12-09
      • 1970-01-01
      • 1970-01-01
      • 2023-04-09
      相关资源
      最近更新 更多