在 ASP.NET MVC 中提供 favicon.ico [英] Serving favicon.ico in ASP.NET MVC

查看:28
本文介绍了在 ASP.NET MVC 中提供 favicon.ico的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于如何在 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:

  • 在我的 RegisterRoutes 方法的开头添加一个条目:

routes.IgnoreRoute("favicon.ico");

  • 将 favicon.ico 放在我的应用程序的根目录中(这也将是我域的根目录).

  • Placing favicon.ico in the root of my application (which is also going to be the root of my domain).

    我有两个问题:

    • 除了我的应用程序的根目录之外,是否没有办法将 favicon.ico 放在其他地方.与 ContentControllers 处于同一级别,这真是令人讨厌.
    • 这个 IgnoreRoute("favicon.ico") 语句是否足够 - 或者我也应该按照 Phil Haack 的博文.我不知道曾经在除根目录之外的任何目录中看到过对 favicon.ico 的请求 - 这将使这变得不必要(但知道如何去做是很好的).

    • 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 and Controllers.
    • 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(/.*)?"});
    

  • 推荐答案

    将 favicon.ico 放在域的根目录中只会真正影响 IE5、IIRC.对于更现代的浏览器,您应该能够包含一个链接标签来指向另一个目录:

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

    您还可以为 IE 以外的浏览器使用非 ico 文件,为此我可能会使用以下条件语句将 PNG 提供给 FF 等,并将 ICO 提供给 IE:

    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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆