Serving favicon.ico in ASP.NET MVC(在 ASP.NET MVC 中服务 favicon.ico)
问题描述
What is the final/best recommendation for how to serve favicon.ico in ASP.NET MVC?
I am currently doing the following:
Adding an entry to the very beginning of my RegisterRoutes method:
routes.IgnoreRoute("favicon.ico");
Placing favicon.ico in the root of my application (which is also going to be the root of my domain).
I have two questions:
- Is there no way to put the favicon.ico somewhere other than the root of my application. It's pretty icky being right there at the same level as
Content
andControllers
. Is this
IgnoreRoute("favicon.ico")
statement sufficient - or should I also do the following as discussed in a blog post from Phil Haack. I'm not aware of ever having seen a request to favicon.ico in any directory other than the root - which would make this unnecessary (but it's good to know how to do it).routes.IgnoreRoute("{*favicon}", new {favicon=@"(.*/)?favicon.ico(/.*)?"});
Placing favicon.ico in the root of your domain only really affects IE5, IIRC. For more modern browsers you should be able to include a link tag to point to another directory:
<link rel="SHORTCUT ICON" href="http://www.mydomain.com/content/favicon.ico"/>
You can also use non-ico files for browsers other than IE, for which I'd maybe use the following conditional statement to serve a PNG to FF,etc, and an ICO to IE:
<link rel="icon" type="image/png" href="http://www.mydomain.com/content/favicon.png" />
<!--[if IE]>
<link rel="shortcut icon" href="http://www.mydomain.com/content/favicon.ico" type="image/vnd.microsoft.icon" />
<![endif]-->
这篇关于在 ASP.NET MVC 中服务 favicon.ico的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 ASP.NET MVC 中服务 favicon.ico
基础教程推荐
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 将 XML 转换为通用列表 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- c# Math.Sqrt 实现 2022-01-01