Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Block 404 FavIco error in ELMAh

I noticed out of the box that ELMAH logs a 404 not found for favico on my local server. How do I suppress this error through a filter? I'm not so familiar with configurating it yet..

like image 231
Caveatrob Avatar asked Apr 17 '09 21:04

Caveatrob


1 Answers

The official elmah Error Filtering page explains a number of ways this 404 favicon error could be supressed.

You could filter out all 404 errors declaratively in the web.config like so. I'm not certain there is a way to only surpress a 404 for a favicon though.

<errorFilter>
    <test>
        <equal binding="HttpStatusCode" value="404" type="Int32" />
    </test>
</errorFilter>

If you wanted to do it programmatically, you could dismiss the error in the ErrorLog or ErrorEmail filtering events as explained in the official docs. The below code is a bit overkill, but it demonstrates how you could filter out only 404 errors for a /favicon.ico request.

void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e)
{
    if (((HttpException)e.Exception.GetBaseException()).GetHttpCode() == 404
       && ((HttpContext)e.Context).Request.Path == "/favicon.ico")
    {
        e.Dismiss();
    }
}

I'd personally prefer to either filter all 404s declaratively through the web.config, or just provide a favicon like Joel suggests.

like image 143
Kurt Schindler Avatar answered Sep 18 '22 13:09

Kurt Schindler