Home > DeveloperSection > Forums > How to serving favicon.ico in ASP.NET MVC
Samuel Fernandes
Samuel Fernandes

Total Post:159

Posted on    February-02-2015 10:25 PM

 ASP.Net C#  ASP.NET MVC  Mvc 

 1 Reply(s)
 1072  View(s)
Rate this:

What is the final/best recommendation for how to serve favicon.ico in ASP.NET MVC?

I am currently doing the following :

  • Adding an entry to the very beginning of my RegisterRoutes method :


  • Placing favicon.ico in the root of my application (which is also going to be the root of my domain).

I have two questions :

  • Is there no way to put favicon.ico somewhere other than the root of my application. Its pretty icky being right there at the same level as Content and Controllers.
  • Is this IgnoreRoute("favicon.ico") statement sufficient - or should I also do the following as discussed in a blog post from Phil Haack. I'm not aware of ever having seen a request to favicon.ico in any directory other than the root - which would make this unnecessary (but its nice to know how to do it).

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

lois waisbrooker
lois waisbrooker

Total Post:70

Posted on    February-02-2015 10:45 PM

Placing favicon.ico in the root of your domain only really affects IE5, IIRC. For more modern browsers you should be able to include a link tag to point to another directory:

<link rel="SHORTCUT ICON" href="http://www.mydomain.com/content/favicon.ico"/>

You can also use non-ico files for browsers other than IE, for which I'd maybe use the following conditional statement to serve a PNG to FF,etc, and an ICO to IE:

<link rel="icon" type="image/png" href="http://www.mydomain.com/content/favicon.png" />

<!--[if IE]>

<link rel="shortcut icon" href="http://www.mydomain.com/content/favicon.ico" type="image/vnd.microsoft.icon" />


Don't want to miss updates? Please click the below button!

Follow MindStick