mvc: does the favicon.ico also look for a controller?
asp.netasp.net Mvcasp.net Mvc-2asp.net Problem Overview
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?
asp.net Solutions
Solution 1 - asp.net
Add this to you global.asax:
routes.IgnoreRoute("favicon.ico");
Solution 2 - asp.net
You can also specify the ignore route with constraints
routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
Solution 3 - asp.net
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).
Solution 4 - asp.net
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.
Solution 5 - asp.net
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.