39

The solution structure of my application is:

enter image description here

Now I am in Login.aspx and I am willing to add favicon.ico, placed in the root, in that page.

What I am doing is:

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

Also I have tried:

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

But these aren't working.

I have cleared the browser cache but no luck.

What will be the path to the favicon.ico from:

  • Login.aspx
  • Site.master

Thank you.


The login page's URL: http://localhost:2873/Pages/Login.aspx and the favicon.ico's URL: http://localhost:2873/favicon.ico.

I am unable to see the favicon.ico enter image description here after changing my code as:

<link id="Link1" rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />  
<link id="Link2" rel="icon" href="/favicon.ico" type="image/ico" />
Tapas Bose
  • 28,796
  • 74
  • 215
  • 331

9 Answers9

71
/favicon.ico

might do the trick
I have tried this on my sample website

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

Try this one in your site put the link in MasterPage,It works :)

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


I have tested in ,
FireFox.
enter image description here
Chrome.
enter image description here
Opera.
enter image description here

Some troubleshoots:
1. Check if your favicon is accessible (correct url) ,goto view source and click on the favicon link
2. Full refresh your browser by Ctrl+F5 every time you make changes.
3. Try searching from SO you may find your related problem here.


Some Links to help you out:
Serving favicon.ico in ASP.NET MVC
Favicon Not Showing
Why is favicon not visible

Community
  • 1
  • 1
DayTimeCoder
  • 4,294
  • 5
  • 38
  • 61
5

I have the same issue. My url is as below

http://somesite/someapplication

Below doesnot work

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

I got it to work like below

<link rel="shortcut icon" type="image/x-icon" href="/someapplication/favicon.ico" />
Ziggler
  • 3,361
  • 3
  • 43
  • 61
  • 1
    @user3308043 - I am sorry that you find my answer ridiculous.. but I just posted the exact things what I did to solve my problem.. this solution went into production and from past one year it is working fine.. and more over I never and ever said dotNetSoldier's answer is wrong. I justed posted one of the solution that I had... I never said others answer are wrong – Ziggler Jun 25 '14 at 15:54
4

resolve the url like this href="<%=ResolveUrl("~/favicon.ico")%>"

Habib
  • 219,104
  • 29
  • 407
  • 436
Domo
  • 39
  • 1
  • 3
3

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

This worked for me. If anyone is troubleshooting while reading this - I found issues when my favicon.ico was not nested in the root folder. I had mine in the Resources folder and was struggling at that point.

Brendan Sluke
  • 857
  • 10
  • 11
2

@Scripts.Render("~/favicon.ico"); Please try above code at the bottom of your Layout file in MVC

Ahsanul
  • 215
  • 2
  • 5
2

Simply:

/favicon.ico

The leading slash is important.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
1
    <link rel="shortcut icon" href="@Url.Content("~/images/")favicon.ico" type="image/x-icon"/ >

This works for me in MVC4 application favicon image is placed in the images folder and it will traverse from root directory to images and find favicon.ico bingo!

ab00764
  • 37
  • 1
  • 7
0

for me, it didn't work without specifying the MIME in web.config, under <system.webServer><staticContent>

<mimeMap fileExtension=".ico" mimeType="image/ico" />
Cătălin Rădoi
  • 1,804
  • 23
  • 43
0

Just make sure your favicon.ico is 16x16, 32x32, 48x48 or 64x64 ... 506x478 for example will not work.

Peladao
  • 4,036
  • 1
  • 23
  • 43
  • While this is useful information, it doesn't answer the original question regarding ASP.NET, and would be better suited as a comment. – Jeremy Caney Apr 25 '23 at 00:22