当我从ASP.NET MVC提供文件时,为什么Chrome浏览器会搜索我的favicon.ico? [英] Why is Chrome searching for my favicon.ico when I serve up a file from ASP.NET MVC?

查看:122
本文介绍了当我从ASP.NET MVC提供文件时,为什么Chrome浏览器会搜索我的favicon.ico?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MVC中有一个控制器,负责从数据库中提供图像.

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

如果我以完全标准的方式在MVC中提供文件,则仍然会发生这种情况.

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

每次我请求图像时,谷歌浏览器都会搜索我的favicon.ico.

Every time I request my image, Google Chrome also searches for my favicon.ico.

为了避免不必要地讨论我也应该关心"其他事情,让我们假设在此示例中我根本不关心缓存,并且我将始终随文件返回HTTP响应200.

To avoid unnecessary discussions about other things "I should also care about" let us assume I do not care for caching whatsoever in this example and I shall always return HTTP response 200 with the file.

在我的控制器中,我返回以下内容:

In my controller I return the following:

return File(fileBytes, contentType);

在检查了Fiddler 2之后,将生成以下响应:

After inspecting Fiddler 2, the following response is generated:

HTTP/1.1 200确定
缓存控制:公共
内容类型:image/gif
ETag:oYu19wKo + KEHkyxZQ2WXAA ==
伺服器:Microsoft-IIS/7.0
X-AspNetMvc版本:1.0
X-AspNet版本:2.0.50727
X-Powered-By:ASP.NET
日期:2009年6月16日,星期二18:48:45 GMT
内容长度:29344

HTTP/1.1 200 OK
Cache-Control: public
Content-Type: image/gif
ETag: oYu19wKo+KEHkyxZQ2WXAA==
Server: Microsoft-IIS/7.0
X-AspNetMvc-Version: 1.0
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Tue, 16 Jun 2009 18:48:45 GMT
Content-Length: 29344

相比之下,这是我第一次(第一次)请求Google徽标时Google在Fiddler中的回复:

By comparison, this is the response in Fiddler from Google when I request (for the first time) the Google logo:

HTTP/1.1 200确定
内容类型:image/gif
上次修改时间:2006年6月7日,星期三,格林尼治标准时间
日期:2009年6月16日,星期二18:50:54 GMT
过期:2010年6月16日,星期三,格林尼治标准时间
缓存控制:公共,最大年龄= 31536000
伺服器:gws
内容长度:8706
年龄:2

HTTP/1.1 200 OK
Content-Type: image/gif
Last-Modified: Wed, 07 Jun 2006 19:42:34 GMT
Date: Tue, 16 Jun 2009 18:50:54 GMT
Expires: Wed, 16 Jun 2010 18:50:54 GMT
Cache-Control: public, max-age=31536000
Server: gws
Content-Length: 8706
Age: 2

但是,在获取我的图片后,Chrome尝试在Chrome中找到我的favicon.ico.请求Google徽标后,它尝试此操作.

However, in Chrome after getting my image Chrome attempts to find my favicon.ico. It does not try this after requesting the Google logo.

有什么想法可能会发生这种情况吗?根据我对HTML的理解,答案必须在响应标头中,因为可以肯定的是,客户端必须继续执行所有操作?请纠正我!

Any ideas why this might be happening? From my understanding on HTML, the answer must be in the response header because surely that is all the client has to go on? Please correct me!

似乎很多人完全误解了这个问题. 问题是不是缺少网站图标和MVC中的错误请求-这是仅在加载图像类型为"IMAGE/JPEG"的图像时请求网站图标的问题",而不是内容类型为"TEXT/HTML"的网页!

EDIT 2: It seems a lot of people have completely misunderstood the problem. The problem is not the lack of a favicon and the erroring requests in MVC - it's the problem of requesting a favicon when only an image is being loaded, with a content type of "IMAGE/JPEG", as opposed to a webpage with a content type of "TEXT/HTML"!!

推荐答案

这与MVC无关.我正在将Webforms与自定义构建的日志服务一起使用,我偶然发现了这篇文章,想知道为什么我的日志中连续出现文件不存在"错误.该文件位于我的开发机器上的本地位置,我的项目中没有favicon.ico文件,并且我尝试使用IE,Firefox和Google尝试查看哪个浏览器是有罪的.

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.

每个从Google Chrome浏览器到我的应用程序的请求都请求一个favicon.ico .我必须开始在本地记录浏览器,以确定实际上是谷歌浏览器才是罪魁祸首.如果麻烦您,我会与Google联系.我只是想确保它不是感染我的chrome的新木马.

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.

这篇关于当我从ASP.NET MVC提供文件时,为什么Chrome浏览器会搜索我的favicon.ico?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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