Filter 按IP地址筛选HttpRequestValidationException Elmah日志

Filter 按IP地址筛选HttpRequestValidationException Elmah日志,filter,ip-address,elmah,Filter,Ip Address,Elmah,我已将其添加到global.asax页面,以帮助我过滤登录elmah时出现的错误,但这仅过滤包含HttpRequestValidationException的任何异常错误。我从McAfee扫描中收到这些错误。我想知道是否有办法检查ip地址,如果ip地址与McAfee的ip地址匹配,则不要记录错误。我试着做: void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e) { if (Server.HtmlEncode(

我已将其添加到global.asax页面,以帮助我过滤登录elmah时出现的错误,但这仅过滤包含HttpRequestValidationException的任何异常错误。我从McAfee扫描中收到这些错误。我想知道是否有办法检查ip地址,如果ip地址与McAfee的ip地址匹配,则不要记录错误。我试着做:

void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e)
{
    if (Server.HtmlEncode(Request.UserHostAddress) == "173.15.183.122" 
        && e.Exception.GetBaseException() is HttpRequestValidationException) {
        e.Dismiss();
    }
}

这对我不起作用。如果有办法获取ip地址,请告诉我需要添加什么名称空间才能正常工作。

我将此名称空间添加到我的web.config文件中,以检查某些ip地址,这将有助于筛选出我不想在数据库中登录的错误

<elmah>
    <errorLog type="Elmah.SQLiteErrorLog, Elmah" connectionStringName="ELMAH.SQLite" />
    <security allowRemoteAccess="yes" />
    <errorFilter>
      <test>
        <and>
          <equal binding="HttpStatusCode" value="500" type="Int32" />
          <regex binding="Context.Request.ServerVariables['REMOTE_ADDR']" pattern="((165.193.42.(6[7-9]|7[0-9]|8[0-6]|13[1-9]|14[0-9]|150))|(161.69.30.(13[6-9]|1[4-5][0-9]|16[0-7]))|(64.14.3.(196|21[4-9]|22[0-9]))|(64.41.168.(24[2-9]|25[0-4]))|(216.35.7.(9[8-9]|1[0-1][0-9]|12[0-6]))|(64.41.140.(9[8-9]|10[0-7]))|(161.69.14.(13[6-9]|1[4-5][0-9]|16[0-7])))$" type="String" />
        </and>
      </test>
    </errorFilter>
</elmah>