按 IP 地址过滤 HttpRequestValidationException Elmah 日志

发布于 2024-11-25 03:10:56 字数 520 浏览 3 评论 0原文

我已将其添加到 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 地址,请告诉我以及我需要添加什么命名空间才能使其正常工作。

I've added this to the global.asax page to help me filter out errors from being logged onto elmah but that only filters any exception error that contains the HttpRequestValidationException. I am receiving these errors from McAfee scans. I was wondering if there was a way to check for an ip address, if the ip address matches that of McAfee, then do not log the error. I tried to do:

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

That isn't working for me. If there is a way to grab an ip address please let me know and what namespace I would need to add to make it work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

许一世地老天荒 2024-12-02 03:10:56

我将其添加到我的 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>

I added this to my web.config file to check for certain ip addresses, which would help filter out what errors I do not want to log in my database.

<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>
掩饰不了的爱 2024-12-02 03:10:56

要在 ErrorLog_Filtering 中执行此操作(我也在 ErrorMail_Filtering 中执行此操作),就像OP尝试做的那样,这会起作用:

if(Context.Request.ServerVariables["REMOTE_ADDR"] == "173.15.183.122") e.Dismiss()

我更喜欢使用 .StartsWith("173.15 .183") 因为这些服务经常使用该范围内的大量 IP(而且我不太关心同一块中其他人的错误是否会被过滤(如果发生的话))

To do it in ErrorLog_Filtering (I also do it in ErrorMail_Filtering) like the OP was trying to do, this will work:

if(Context.Request.ServerVariables["REMOTE_ADDR"] == "173.15.183.122") e.Dismiss()

I prefer using .StartsWith("173.15.183") as these services often use lots of IPs in that range (and I don't care too much if an error from someone else in that same block gets filtered if it was to ever happen)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文