ASP.NET MVC: Ignore requests to favicon.ico

One problem I faced when writing my example pet portal on ASP.NET MVC was Google Chrome’s request to favicon.ico that doesn’t exist. IE8 that I use (8.0.7000.0) doesn’t make these blind requests to discover that favicon.ico is not there. Solution to my problem was very simple.

Just add the ignore rule for favicon.ico to Global.asax file, in the beginning of RegisterRoutes method:

public static void RegisterRoutes(RouteCollection routes)
"{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?"

// Other route definitions follow here

The rule for favicon works for all folders in your application. There is also one other interesting thing. If you ignore some route then ASP.NET MVC lets those requests to files directly to web server. It doesn’t direct them to controllers.

Gunnar Peipman

Gunnar Peipman is ASP.NET, Azure and SharePoint fan, Estonian Microsoft user group leader, blogger, conference speaker, teacher, and tech maniac. Since 2008 he is Microsoft MVP specialized on ASP.NET.

    8 thoughts on “ASP.NET MVC: Ignore requests to favicon.ico

    • February 27, 2009 at 6:07 pm

      I was adding some error logging code to my application last weekend when I kept getting the “File not found” error for favicon.ico. In the end i just created the damn thing to shut it up. But I prefer your solution, thanks!

    • April 22, 2009 at 4:32 pm

      Thank you for the solution, I’m going to add a global error handler for my current MVC project and favicon.ico request is very annoying.

    • May 28, 2009 at 9:56 am

      Perfect! This will really help, as I’m using an error handler to email me site errors and continually get emails regarding favicon.ico.

    • January 25, 2017 at 7:42 am

      Sorry to say but above solution doesn’t work. I cleared the history before running application in chrome.

    • January 25, 2017 at 7:45 am

      Not sure what you mean solution doesn’t work. It doesn’t make browsers to stop asking for favicon. It just doesn’t let these requests through MVC pipeline if favicon is missing.

    • January 27, 2017 at 10:15 am

      Ok thanks, I do have favicon.ico file in my application. When i browse my application with Google Chrome the console message i can see is
      “GET https://localhost/favicon.ico 404 (Not Found)”.

    • February 2, 2017 at 10:15 am

      What happens when you make direct request to this file through browser? Is it displayed then?

    Leave a Reply

    Your email address will not be published. Required fields are marked *