mvc: does the favicon.ico also look for a controller?

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?


Solution 1:

Add this to you global.asax:

routes.IgnoreRoute("favicon.ico");

Solution 2:

You can also specify the ignore route with constraints

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

Solution 3:

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:

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.