14

I have a favicon in my ASP.NET project that's not showing up. I have a masterpage located at ~/MasterPages/MasterPage.master that holds the favicon. My markup is as follows:

<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
<link rel="icon" href="/favicon.ico" type="image/x-icon"/>

The favicon is located in the project root. The dimensions are 16x16 and it's 32-bit depth. I've cleared my browser's cache, rebooted and nothing is working. Any suggestions as to what I should do?

Halcyon
  • 14,631
  • 17
  • 68
  • 99
  • 1
    Could it be the file is not being accessed properly? Depending on the file structure, you may not need the `/` in front of favicon.ico. – Jason Gennaro Jun 09 '11 at 16:31
  • 1
    Are you able to navigate directly to the favicon.ico file in the browser? i.e `http://projectroot/favicon.ico`? – CatDadCode Jun 09 '11 at 18:09
  • 1
    When I hit the favicon directly, I get this error in Chrome: This webpage has a redirect loop The webpage at http://root/login.aspx?returnurl=%2ffavicon.ico has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer. – Halcyon Jun 09 '11 at 18:35
  • 1
    ctrl f5 is doing the trick for me. – Bryan Mudge Sep 19 '15 at 16:02

7 Answers7

20

Try placing a ~ and set the link elements to runat=server

<link runat="server" rel="shortcut icon" href="~/favicon.ico" type="image/x-icon" />
<link runat="server" rel="icon" href="~/favicon.ico" type="image/ico" />

This also needs to be done in the <head> section of the page.

MattC
  • 3,984
  • 1
  • 33
  • 49
  • 1
    If I am not mistaken the `~` on `` tag works even without `runat="server"` – BrunoLM Jun 09 '11 at 16:36
  • 1
    @BrunoLM - ~ requires a virtual path mapping, hence needs to run in managed code to interpret the virtual path of the site. – Adam Tuliper Jun 09 '11 at 16:43
  • 1
    Adding the tilde '`' and runat="server" attributes fixed it. Thank you! – Halcyon Jun 09 '11 at 18:54
  • 1
    What if my current page is in a folder? The ~ path will be resolved to http://example.com/Myfolder/favicon.ico – Germstorm Jan 15 '12 at 19:09
  • 1
    Made these changes to the lines I got from realfavicongenerator.net and that solved all my issues. (using MVC asp.net) – LJ Codes May 11 '17 at 12:16
  • 1
    Referencing the assets in the `` tag was the critical part here. Easy to forget to do this because most guides leave that out, and an asp.net site will generally have the head tag contained within a `_Layout.cshtml` partial. – FoxDeploy Jun 05 '19 at 15:05
10

Try to leave the type away, clear the browser cache and go to the favicon address manually and add some parameters to it. That should fix it. Maybe you could tell me your website address, then I will look, if it shows up here.

1' OR 1 --
  • 1,694
  • 1
  • 16
  • 32
6

Right click on the solution and go to Properties. Under Application > Resources change the default icon to your chosen one.

Coder
  • 117
  • 2
  • 13
4

Load up fiddler http://www.fiddler2.com/fiddler2/ and look for the request from the browser for it - that will show you if its successful, a cache issue, etc.

Adam Tuliper
  • 29,982
  • 4
  • 53
  • 71
2

In a .NET Core app (MVC template) try moving the favicon.ico file to the lib folder instead of the wwwroot folder.

Ken
  • 474
  • 6
  • 8
2

I finally solved this problem by renaming favicon.ico to myicon.ico, and reference it in the head <link rel="icon" href="~/myicon.ico" type="image/x-icon" />

Tracy Zhou
  • 714
  • 1
  • 7
  • 11
1

I used this method in ASP.NET:

<link rel="shortcut icon" type="image/ico" href="~/favicon.png">
Fahimeh Ahmadi
  • 813
  • 8
  • 13