在ASP.NET MVC服务favicon.ico的 [英] Serving favicon.ico in ASP.NET MVC

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

问题描述

什么是如何在ASP.NET MVC?

What is the final/best recommendation for how to serve favicon.ico in ASP.NET MVC?

我目前在做以下内容:


  • 添加我的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的某个地方。它的pretty恶心是那里在同一级别为内容控制器

    • 这是 IgnoreRoute(的favicon.ico)语句不够的 - 或者我应该做的也是在<一个讨论了以下href=\"http://haacked.com/archive/2008/07/14/make-routing-ignore-requests-for-a-file-extension.aspx\">a从菲尔哈克博客帖子。我不知道有史以来看过比根以外的任何目录下的favicon.ico请求 - 这将使这种不必要的(但很高兴知道如何做到这一点)

    • Is there no way to put favicon.ico somewhere other than the root of my application. Its 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 its nice 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"/>
    

    您也可以使用非ICO文件比IE等浏览器,为此我可能使用以下条件语句以服务为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天全站免登陆