How to add favicon.ico in ASP.NET site

2020-05-19 02:50发布

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

9条回答
贼婆χ
2楼-- · 2020-05-19 02:59

Check out this great tutorial on favicons and browser support.

查看更多
等我变得足够好
3楼-- · 2020-05-19 02:59

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

查看更多
女痞
4楼-- · 2020-05-19 03:01

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

查看更多
虎瘦雄心在
5楼-- · 2020-05-19 03:03

Simply:

/favicon.ico

The leading slash is important.

查看更多
Viruses.
6楼-- · 2020-05-19 03:03
    <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!

查看更多
叼着烟拽天下
7楼-- · 2020-05-19 03:07

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

<mimeMap fileExtension=".ico" mimeType="image/ico" />
查看更多
登录 后发表回答