C# 如何在 ASP.NET 站点中添加 favicon.ico
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9963584/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add favicon.ico in ASP.NET site
提问by Tapas Bose
The solution structure of my application is:
我的应用程序的解决方案结构是:


Now I am in Login.aspx and I am willing to add favicon.ico, placed in the root, in that page.
现在我在 Login.aspx 中,我愿意在该页面中添加放置在根目录中的 favicon.ico。
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:
从以下位置到 favicon.ico 的路径是什么:
- Login.aspx
- Site.master
- 登录.aspx
- 网站管理员
Thank you.
谢谢你。
The login page's URL: http://localhost:2873/Pages/Login.aspxand the favicon.ico's URL: http://localhost:2873/favicon.ico.
登录页面的 URL:http://localhost:2873/Pages/Login.aspx和 favicon.ico 的 URL:http://localhost:2873/favicon.ico。
I am unable to see the favicon.ico
after changing my code as:
将代码更改为以下内容后,我无法看到 favicon.ico :
<link id="Link1" rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<link id="Link2" rel="icon" href="/favicon.ico" type="image/ico" />
采纳答案by Owais Qureshi
/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 :)
在你的网站上试试这个,把链接放在 MasterPage 中,它有效:)
<link rel="shortcut icon" type="image/x-icon" href="~/favicon.ico" />
I have tested in ,
FireFox.
Chrome.
Opera.
我已经在 ,
FireFox 中进行了测试。
铬合金。
歌剧。
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+F5every time you make changes.
3. Try searching from SO you may find your related problem here.
一些故障排除:
1. 检查您的收藏夹图标是否可访问(正确的 url),转到查看源代码并单击收藏夹图标链接
2.每次进行更改时按Ctrl+F5完全刷新浏览器。
3. 尝试从 SO 搜索您可能会在这里找到您的相关问题。
Some Links to help you out:
Serving favicon.ico in ASP.NET MVC
Favicon Not Showing
Why is favicon not visible
一些可以帮助您的链接:
在 ASP.NET MVC
Favicon Not Showing 中Serving favicon.ico
为什么 favicon 不可见
回答by Marc Gravell
Simply:
简单地:
/favicon.ico
The leading slash is important.
前导斜杠很重要。
回答by Domo
resolve the url like this href="<%=ResolveUrl("~/favicon.ico")%>"
像这样解析网址 href="<%=ResolveUrl("~/favicon.ico")%>"
回答by Kevin Babcock
Check out this great tutorialon favicons and browser support.
查看有关网站图标和浏览器支持的精彩教程。
回答by Ziggler
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" />
回答by Ahsanul
@Scripts.Render("~/favicon.ico"); Please try above code at the bottom of your Layout file in MVC
@Scripts.Render("~/favicon.ico"); 请在MVC中的布局文件底部尝试上面的代码
回答by ab00764
<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!
这对我来说适用于 MVC4 应用程序 favicon 图像放置在图像文件夹中,它将从根目录遍历图像并找到 favicon.ico 宾果游戏!
回答by Brendan Sluke
<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.
这对我有用。如果有人在阅读本文时进行故障排除 - 当我的 favicon.ico 未嵌套在根文件夹中时,我发现了问题。我在资源文件夹中有我的,并且当时正在挣扎。
Thanks!
谢谢!
回答by C?t?lin R?doi
for me, it didn't work without specifying the MIME in web.config, under <system.webServer><staticContent>
对我来说,如果没有在 web.config 下指定 MIME,它就不起作用 <system.webServer><staticContent>
<mimeMap fileExtension=".ico" mimeType="image/ico" />

