按 IP 地址过滤 HttpRequestValidationException Elmah 日志
我已将其添加到 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我将其添加到我的 web.config 文件中以检查某些 IP 地址,这将有助于过滤掉我不想登录数据库的错误。
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.
要在
ErrorLog_Filtering
中执行此操作(我也在ErrorMail_Filtering
中执行此操作),就像OP尝试做的那样,这会起作用:我更喜欢使用
.StartsWith("173.15 .183")
因为这些服务经常使用该范围内的大量 IP(而且我不太关心同一块中其他人的错误是否会被过滤(如果发生的话))To do it in
ErrorLog_Filtering
(I also do it inErrorMail_Filtering
) like the OP was trying to do, this will work: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)