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

喜欢而已 提交于 2019-11-27 20:21:00
Steve

Add this to you global.asax:

routes.IgnoreRoute("favicon.ico");

You can also specify the ignore route with constraints

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

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).

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.

yoel halb

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!