'Filter HttpRequestValidationException Elmah Logs by IP Address

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.



Solution 1:[1]

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)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Matt Kemp