66

I get an error:

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

Then I thought: how does the framework know for which files it has to instantiate a controller, because the same thing is true for script, css and other files?

(never thought of that, but now the favicon is complaining, I was wondering....)

But back to the error, why does that occur?

1

5 Answers 5

112

Add this to you global.asax:

routes.IgnoreRoute("favicon.ico");
1
  • 4
    Thanks, that worked great. I was using ELMAH and it kept giving me an error. To make sure no error about favicon.ico appears in ELMAH, make sure to also add the file "favicon.ico" in the root folder of your site.
    – mateuscb
    Sep 22, 2011 at 22:43
19

You can also specify the ignore route with constraints

routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
4
  • Is there any rationale behind using a complex approach when the simple routes.IgnoreRoute("favicon.ico"); seems to be enough? Perhaps some browser tries to automatically get the favicon, and uses a funny URL?
    – ANeves
    Apr 17, 2012 at 9:59
  • 3
    The simple approach would work only if favicon.ico is placed in the root of the site as @mateuscb pointed out in his comment, however if one places it somewhere else as described in stackoverflow.com/questions/487230/… then we need this more complicated approach.
    – yoel halb
    Jul 17, 2012 at 20:45
  • 1
    Anyone using this code snippet should be aware that there is a syntax error as "routes" should be lowercase since we are dealing with an instance and not with a type
    – yoel halb
    Jul 17, 2012 at 20:50
  • 2
    @yohal - whoops - fixed it as per haacked.com/archive/2008/07/14/… Jul 17, 2012 at 21:58
15

The top answers are correct.

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

But for newer versions of MVC you must add this at the top of the RegisterRoutes method in RouteConfig.cs (so somewhere before routes.MapRoute(..) is called).

3

You are probably getting this with the VS web server. Right?

You wouldn't get this with IIS since IIS (by default) handles requests for images (.ico, .jpg, .gif, et cetera) and therefore they don't make it to your app.

3
  • my first reaction was yes, but no, it's als on iis6 + win2003
    – Michel
    Jan 9, 2011 at 16:16
  • 1
    Also on IIS 7. You must add the ignoreroute for favicon and for robots.txt as well. Sep 12, 2011 at 17:10
  • 2
    IIS 7 has this "integrated pipeline" thing where HTTP handlers get a crack at pretty much any URL that hits the site, IIRC.
    – cHao
    Sep 13, 2012 at 14:00
0

Interesting as it sounds I got this error only if I had checked the "Enable Just My Code" option under tools->options->debugging, and as soon as I unchecked it I am no longer getting this error.

Note however that it appears that the error is still being thrown behind the scenes but being caught immediately internally, so the best solution is to code in the global.asax to ignore it as the other answers suggest.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.