2

I am using ASP.NET MVC 3. I am also using Autofac and MVC Extensions. The error that I initally got was:

The controller for path '/favicon.ico' was not found or does not implement IController.

I read a couple of posts and they all recommended that I put in the following:

Routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });

Then I started to get the following error:

File does not exist.
ExceptionType:HttpException Stacktrace:
     at System.Web.StaticFileHandler.GetFileInfo(String virtualPathWithPathInfo, String physicalPath, HttpResponse response)
     at System.Web.StaticFileHandler.ProcessRequestInternal(HttpContext context, String overrideVirtualPath)
     at System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state)
     at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
     at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

The error isn't telling me much as I don't know what what file it is trying to open up? How would I resolve this issue? I'm not using a favicon, I don't want one. I am using Internet Explorer 8.

Brendan Vogt
  • 25,678
  • 37
  • 146
  • 234
  • 1
    The error suggests that the favicon doesn't exists in the location where it is being search for (the ignore route certainly works because StaticFileHandler has picked up the request). Try using `Url.Content` in order to generate proper path to favicon and check if the error is still there. There might be other reasons so I'm not posting this as an answer yet. – tpeczek Nov 12 '12 at 08:25
  • I'm not using a favicon. – Brendan Vogt Nov 12 '12 at 08:30
  • Browsers automatically check if a website has a favicon, so you will (almost) always get a `GET` request for one, no matter if your application has a favicon or not. The MVC engine is then of course trying to process this request. – Treb Nov 12 '12 at 08:47
  • So you are fighting with Google Chrome’s blind request for favicon - sorry I didn't understood the question correctly. – tpeczek Nov 12 '12 at 08:47
  • I don't have a favicon and I don't want one, but it is looking for one. I am using IE8, not Chrome. – Brendan Vogt Nov 12 '12 at 08:51
  • @BrendanVogt Where you are seeing this exception? ELMAH? – VJAI Nov 12 '12 at 09:07
  • @BrendanVogt I have updated answer with detailed explanation and some possible workarounds. – tpeczek Nov 12 '12 at 09:45

3 Answers3

2

The request for favicon.ico is being blindly made by most modern browsers and they are expecting a 404 (File Not Found) if there is no favicon (this is proper behaviour). Below you can find a quote from HTML5 working draft regarding Link type "icon" :

In the absence of a link with the icon keyword, for documents obtained over HTTP or HTTPS, user agents may instead attempt to fetch and use an icon with the absolute URL obtained by resolving the URL /favicon.ico against the document’s address, as if the page had declared that icon using the icon keyword.

The reason why you see the exception is that the web development server or IIS configured to use Managed/Integrated Pipeline Mode puts all requests through Global.asax (including errors).

You can try to prevent the browsers from making the requests by creating following dummy link to favicon:

<html>
    <head>
        <link rel="shortcut icon" href="#" />
        ...
    </head>
...
</html>

You can also create yourself an empty file for favicon or filter out the errors by checking HttpException.GetHttpCode() for 404 and ((System.Web.HttpApplication)Sender).Context.Request.Url for /favicon.ico.

tpeczek
  • 23,867
  • 3
  • 74
  • 77
0

If you don't want a favicon in your site but still you want to get rid of this errors, you could create a file of size 0 bytes and name it as favicon.ico.

VJAI
  • 32,167
  • 23
  • 102
  • 164
0

alternative rule to try is just plain and simple:

// add ignore route for favicon.ico
routes.IgnoreRoute("favicon.ico");
cpoDesign
  • 8,953
  • 13
  • 62
  • 106