May 12, 2018

Sreekanth B

How To Add favicon.ico In ASP.NET MVC Application

How To Add favicon.ico In ASP.NET MVC Application?

What is the 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).


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=""/>

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="" />

<!--[if IE]>

<link rel="shortcut icon" href="" type="image/" />


specific ASP.NET MVC it would be better to use either Razor syntax:

<link rel="icon" href="@Url.Content("~/content/favicon.ico")"/>

Or traditionally

<link rel="icon" href="<%= Url.Content("~/content/favicon.ico") %>"/>
rather than

<link rel="icon" href=""/>.

Subscribe to get more Posts :