Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Favicon only shows in Homepage ASP.NET MVC

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?

like image 827
Kendall H. Avatar asked May 31 '16 04:05

Kendall H.


2 Answers

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

like image 161
Nkosi Avatar answered Oct 04 '22 11:10

Nkosi


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>
like image 26
NightOwl888 Avatar answered Oct 04 '22 12:10

NightOwl888