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

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.
Every time I request my image, Google Chrome also searches for my favicon.ico.
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);
After inspecting Fiddler 2, the following response is generated:
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
By comparison, this is the response in Fiddler from Google when I request (for the first time) the Google logo:
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
However, in Chrome after getting my image Chrome attempts to find my favicon.ico. It does not try this after requesting the Google logo.
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!
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"!!

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.

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. :/

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.

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)

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.

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

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

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

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

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.

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

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)

Related

302 Moved Temporarily, BUT when I open it on the browser directly it's ok

I put a script tag on my html page, and run it on firefox, firebug tell me that the script is '302 Moved Temporarily',
but when I open that script in new tag on the browser, it's 200 ok(response conrrectly)~~
I saw that when 302 the server response a redirect page, here's the header:
Cache-Control max-age=2592000
Connection keep-alive
Content-Length 154
Content-Type text/html
Date Tue, 26 Mar 2013 08:10:33 GMT
Expires Thu, 25 Apr 2013 08:10:33 GMT
Location http://www.xxxx.com/error/index.html
Server nginx
if I put the script on other server(no error redirecting page settings), will not come across this question
Anyone met the same question with me?
I don't want to put the file on other server and have no permission to config this server.
Is there a solution to this?
Thanks a lot and forgive my poor English.
I am having extreme difficulty understanding what you are asking so I'm just making a guess. If a 302 has a cache control header on it that tells the browser that it's allowed to cache the redirected page, the browser may do so. For example, here's some documented improvements in IE 9 with respect to caching redirect pages: http://blogs.msdn.com/b/ie/archive/2010/07/14/caching-improvements-in-internet-explorer-9.aspx

OutputCache has no effect

I'm back on a MVC app where I thought that output caching was working as expected. However, while revisiting it, I see that the OutputCache attribute I use has no effect (Duration is set to a high value). Whether I add it or not, the breakpoint in my action is always hit and Firebug shows me a 200 OK on the requested page in each case.
In a more complex action where I use VaryByCustom, the GetVaryByCustomString method in global.asax is never called. I know that it was called in the past since I was able to debug there but now it's not.
I wonder what I did to break this... Any idea?
(in order to not only test localhost, I use a dyndns.org address so that it's a valid external URL. I also use IIS).
Update: when I use the localhost URL, targetting the same url does not enter the action code again. Hitting F5 does. When using the internet URL it always visits the action code.
Update 2: Fiddler is showing this in the response headers:
200 OK
Cache:
Cache-Control: public, no-cache="Set-Cookie", max-age=86400
Date: Mon, 16 Jul 2012 19:38:46 GMT
Expires: Tue, 17 Jul 2012 19:38:46 GMT
Vary: *
Expires = Date + 24h each time I request the same url, which shows that a new page is served each time. Also I should get 200 the first time and 304 thereafter.
Just discovered the culprit, which is contextual to my application:
If I remove the 51degrees.mobi nuget package from my app, it just works again. Put it back (even without using its features) and caching is dead. Well, in fact there are 2 cases:
If you just add the package, GetVaryByCustomString is never called. The action method is called once correctly and then is served from the cache.
If you add the package AND you also use a CompressFilter attribute, then GetVaryByCustomString is never called AND the action method is always called (no page served from the cache).
I posted to their forums to report this issue.
Update: these issues appear starting with 51degrees version 2.1.4.9. I notice that this is the first version using Microsoft.Web.Infrastructure, in case this is relevant...
Update 2: they found the cause of this issue and it will be fixed.

web resource caching issue

I have a website with some css and images.
I pushed some changes about the css and images to live.
I open IE/Firefox and type the URL to my website and hit return.
Then nothing is updated. I saw the IE/FF is not even try to ask for update, so there is no 304 returned.
I have to F5 fresh to get new content, but my users may not do this.
Does anybody know what to do?
Thanks
What is your HTTP server? You'll need to have it set the Cache-Control: no-cache HTTP header to disable caching at all your users.

Defined client cache seems to get ignored

I'm not sure what I'm doing wrong but despite of everything I've tried, I don't seem to be able to get the clients to cache my static resources.
In my web.config, I've added the following entry:
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="30.00:00:00" />
</staticContent>
According to the documentation, this should send a response header to the client browser to let it know we want to keep static content cached for 30 days.
If I use fiddler to see what the client is receiving, it looks like my web.config addition gets ignored completely.
Below is what fiddler is reporting:
Cache-Control: no-cache
Date: Mon, 05 Dec 2011 14:09:44 GMT
Expires: -1
Pragma: no-cache
Vary: Accept-Encoding
I don't have any headers in IIS overriding this so I'm not sure what is it that I am missing. Any help would be greatly appreciated.
I cracked this but it took a while. You're trying to force 304s from the server (no change). It differs with IIS versions.
It's best achieved by having all you're static content in one directory
(e.g. content so you'd have /content/css /content/js etc)
Then you just have to ensure everything under that directory doesn't expire for, say, 30 days.
IIS7
Much easier. Easiest way - add a web.config to the content directory referred to above. This web.config will have just the expires directive:
<system.webServer>
<staticContent>
<clientCache
cacheControlMaxAge="30.00:00:00"
cacheControlMode="UseMaxAge" />
</staticContent>
</system.webServer>
IIS6
You'll need to manipulate the metabase. It's not XML in IIS6, follow the instructions here: IIS6 ETags metabase commands
We used both the above and simple viewing of firebug shows 304s coming through.

Publishing ASP.NET MVC3 Website

This is really confusing me, it just does not want to work. I did exactly like the walk-through on MSDN says and I still get Under Construction page everytime I browse to the domain (fisharwe.com). Ok enough with the nag, here's what I did:
In Visual Studio 2010, I right clicked the project name and chose Publish. I chose to publish to the File System and everything went okey. Then I used CuteFTP to upload the files to the httpdocs folder (Plesk control panel), the live support guy said this is supposed to be the public folder. Finally, I tried to open the site and still nothing shows up... All I get is:
The site you are trying to view does
not currently have a default page. It
may be in the process of being
upgraded and configured.
So what's going on?
Judging by the following response header i'm seeing returned on your domain it seems your running IIS6;
Content-Length 1433
Content-Type text/html
Content-Location http://fisharwe.com/iisstart.htm
Last-Modified Fri, 21 Feb 2003 18:48:30 GMT
Accept-Ranges bytes
Etag "0938ad3d9d9c21:2f56e6"
Server Microsoft-IIS/6.0
X-Powered-By ASP.NET
Date Mon, 18 Apr 2011 18:04:19 GMT
Take a good look at this article by Phil Haacked, hope it's helpfull. He explains how to set up an mvc website on iis6
You need to configure the server to send all requests through ASP.Net.

Resources