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.

See also

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

Leave a Reply

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