Why is Chrome searching for my favicon.ico when I serve up a file from ASP.NET MVC?

后端 未结 12 1399
死守一世寂寞
死守一世寂寞 2020-12-16 14:32

I have a controller in MVC serving up images from a database.

EDIT: This still happens if I serve up a file over completely standard means in MVC.

Eve

相关标签:
12条回答
  • 2020-12-16 14:32

    The actual answer: It's a known, verified bug. *(recently fixed!... maybe?)

    Looks like a known, longstanding issue with Chrome: http://crbug.com/39402

    If you want it fixed sooner, star the issue. More people starring the issue will likely increase its priority and possibly get it fixed faster.


    ****UPDATE 1***: As of May 15 of this year (2013)--four years after this question was asked--it looks like the issue has been fixed in version 29: http://crbug.com/39402#c47

    Feel free to undo all your hacks and workarounds. :]

    ****UPDATE 2 (2015-01)***: This is apparently still an issue for some users, according to the same issue link. :/

    0 讨论(0)
  • 2020-12-16 14:32

    I ran into this problem a while back and got around it by ignoring the specific route by adding

    routes.IgnoreRoute("{*favicon}", new { favicon = ".*/favicon\\.ico" });
    

    into the RegisterRoutes method in Global.asax.

    0 讨论(0)
  • 2020-12-16 14:36

    You can add something like this within your web.config file to make sure that the favicon.ico is cached on the client and is not being requested every time.

    <location path="favicon.ico">
        <system.webServer>
            <httpProtocol>
                <customHeaders>
                    <add name="Cache-Control" value="public, max-age=31536000" />
                 </customHeaders>
            </httpProtocol>
        </system.webServer>
    </location>
    

    You can/should do the same for any images / .js and css files

    0 讨论(0)
  • 2020-12-16 14:36

    If you check your project setting it says default icon somewhere. Remove that?

    0 讨论(0)
  • 2020-12-16 14:41

    Its important to put in an ICON link into your masterpage or some browsers will try to find favicon.ico for all directories and not just globally once per done.

     <link rel="SHORTCUT ICON" href="<%= Url.Content("~/content/images/rr-favicon.ico") %>"/>
    

    It seems google toolbar is the guilty party judging by my logs (and IE6 of course). They both will make requests for directories other than the root

     Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
     Mozilla/4.0 (compatible; GoogleToolbar 6.2.1910.1554; Windows 6.0; MSIE 8.0.6001.18828)
    
    0 讨论(0)
  • 2020-12-16 14:42

    Do you have a favicon? If not, perhaps that's why Chrome is attempting to find it every time for your website. For google it already has the favicon cached.

    0 讨论(0)
提交回复
热议问题