19

我正在使用 Elmah 登录 ASP.NET MVC 项目,并且我收到了很多路径 /prx2.php 的 404 错误,而路径 /prx2.php 又将哈希作为查询字符串参数传递。

我认为这是一个试图发现漏洞的扫描程序。因为我没有运行 PHP,所以我很安全!但是我想阻止 ELmah 报告这个错误。

在不实际创建 /prx2.php 页面的情况下,将这些类型的错误排除在报告之外的最佳方法是什么。我也想在配置文件中执行此操作,而不是以编程方式执行此操作。

有任何想法吗?

4

2 回答 2

18

Elmah 支持错误过滤 -错误过滤链接

这应该可以为您解决问题。您可以通过代码定义过滤器 - 在 Global.asx 文件中,或在 elmah 本身的 xml 配置中

于 2010-01-15T13:13:07.017 回答
4

第 1 步:配置配置部分以包括 elmaherrorFilter部分:

<configSections>
  <sectionGroup name="elmah">
    <!-- ... -->  
    <!-- this is the important part -->
    <section name="errorFilter" requirePermission="false" 
      type="Elmah.ErrorFilterSectionHandler, Elmah"/>
  </sectionGroup>
</configSections>

Step2:在<elmah>部分中配置过滤器本身。

<elmah>
  <!-- ... -->
  <errorFilter>
    <test>
      <and>
        <equal binding="HttpStatusCode" value="404" type="Int32" />
        <!-- you may want to consider something more generic like pattern="/.+[.]php" -->
        <regex binding="Context.Request.Url" pattern="/prx2.php" />
      </and>
    </test>
  </errorFilter>
</elmah>    

Step3:Elmah.ErrorFilterModule在你的应用程序模块中包含

包含 http 模块的现代(IIS7+)版本:

<system.webServer>
  <modules runAllManagedModulesForAllRequests="true">
    <!-- ... -->
    <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" 
      preCondition="managedHandler" />
  </modules>
</system.webServer>

包括 http 模块的旧版(旧 IIS)版本:

<system.web>
  <httpModules>
    <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
  </httpModules>
</system.web>
于 2017-01-19T10:41:55.560 回答