I just add this in the head
of my _Layout.cshtml.
<head>
<link rel="shortcut icon" type="image/ico" href="~/Images/favicon.ico">
</head>`
the icon is showing but only in homepage, what is the reason for that?
In general, it is a good practice to put all favicon-related files in the root directory of the web site. Some browsers will always check for favicon.ico in the root folder.
<head>
<link rel="shortcut icon" type="image/ico" href="~/favicon.ico">
</head>
Also, take a look at these posts
Is putting your favicon.ico file in a non-root path a bad idea?
Serving favicon.ico in ASP.NET MVC
Rather than moving the favicon.ico
file into the root, you can easily add a rewrite rule using the IIS IRL rewrite module, which will make it act like it is in the root directory even though it is where you would rather keep it.
Simply install the rewrite module, and drop this into your root web.config
file.
<configuration>
<system.webServer>
<rewrite>
<rule name="Rewrite favicon.ico location from root to physical">
<match url="^favicon\.ico$"/>
<action type="Rewrite" url="images/favicon.ico"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Of course, you can also specify the actual location for the file in your _Layout.cshtml
file for those browsers that will respect the shortcut icon tag.
<head>
<link rel="shortcut icon" type="image/ico" href="@Url.Content("~/Images/favicon.ico")">
</head>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With