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

后端 未结 12 1400
死守一世寂寞
死守一世寂寞 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:45

    You should set the Expires header to tell the browser how long it should use its local copy.

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

    It appears for me that Chrome requests a favicon for its own tabs - I kept getting 404s (because my favicon is somwhere else and my pages know it) till I did some tests and realized it was Chrome making direct requests to the favicon file. No real fix except making a rewrite to the real file I guess

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

    Chrome browser could work with Google site in another way than with any other site, so, at first, I would recommend to check if it looks for favicon.ico every time somewhere else, for example, on StackOverflow.

    I would also check if Firefox does the same with your site. I think favicon.ico should be requested only one time per browser run even if it isn't present on site. This could be bug in Chrome version you use.

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

    This has nothing to do with MVC. I am using webforms with a custom built log service and I stumbled upon this post wondering why I had continuous 'File does not exist' errors in my logs. This is locally on my development machine, I have no favicon.ico files in my projects, and I have tried IE, Firefox and Google trying to see which browser is the guilty party.

    Every request from Google Chrome to my apps makes a request for a favicon.ico. I had to start logging browser locally to determine that it was in fact googles browser that is the culprit. I'd contact google if it bothers you. I just wanted to make sure it wasn't some new trojan infecting my chrome.

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

    one thing you could do is have MVC ignore any request for *.ico so that you don't get any exceptions while debugging.

    Should be something like this:

    routes.MapRoute("ignore-favicon", "{*path}", null, new {path = ".*/favicon\\.ico"});
    

    That URL pattern matches everything, but then we constrain it to only match anything ending in favicon.ico. (I haven't tested this)

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

    This SO question/answer explains how to serve the Favicon to the browser by using routes.

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