I Have a specific set of HTTP response headers I'm trying to recreate in ASP.NET.
Here is how it looks in Fiddler (Raw):
HTTP/1.1 200 OK
Content-Length: 570746
Content-Type: audio/wav
Last-Modified: Wed, 19 May 2010 00:44:38 GMT
Accept-Ranges: bytes
ETag: "379d676ecf6ca1:3178"
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Date: Tue, 05 Oct 2010 18:35:18 GMT
Here is how it looks on the Headers tab (same data. Different view)
I am trying to recreate the same set of headers (different values of course) with code, on an ASP.NET page. The biggest problem is with the cache settings and the ETag. It usually shows some "private" or similar cache setting and no ETag value, even though I'm trying to set it explicitly with
Response.Cache.SetETag
Have you tried something like this:
if (Response.Headers("ETag") == null)
Response.AddHeader("ETag", "379d676ecf6ca1:3178")
else
Response.Headers("ETag") = "379d676ecf6ca1:3178";
Related
I have issues convincing Firefox 71 to cache a large (>4MB) image. I notice both in developer tools (as being logged) and during normal operations (as per loading delay) that the image is loaded every time the page is accessed.
Although I thought I provided all the necessary response headers, Firefox is not sending If-Modified-Since or If-None-Match request headers.
These are the HTTP headers my server is sending:
$ HEAD https://😉/image.png
200 OK
Cache-Control: public, max-age=31536000, immutable
Connection: close
Date: Sat, 04 Jan 2020 19:52:20 GMT
Accept-Ranges: bytes
ETag: "564cd5fb-4484b0"
Server: nginx/1.14.0 (Ubuntu)
Content-Length: 4490416
Content-Type: image/png
Last-Modified: Wed, 18 Nov 2015 19:48:11 GMT
Client-Date: Sat, 04 Jan 2020 19:52:20 GMT
Client-Peer: 😛
Client-Response-Num: 1
Client-SSL-Cert-Issuer: /C=US/O=Let's Encrypt/CN=Let's Encrypt Authority X3
Client-SSL-Cert-Subject: /CN=😉
Client-SSL-Cipher: ECDHE-RSA-CHACHA20-POLY1305
Client-SSL-Socket-Class: IO::Socket::SSL
The web page loads the image via JavaScript:
let mapImg = new Image();
mapImg.src = 'image.png';
I believe I did everything according to documentation and wonder if I made some wrong combination of response headers, encryption, compression, and loading method?
I have made a request for a video which returns a video with an ETAG.
When I make a request for the same video again, I can see the If-non-match header passed from the browser with the Etag but instead of 304 returned, the video is downloaded again with a 200 OK response.
In fiddler for the very first request for the video, the response is:
HTTP/1.1 200 OK
Cache-Control: max-age=10
Content-Length: 76278442
Content-Type: video/mp4
Last-Modified: Wed, 21 Aug 2013 08:47:29 GMT
ETag: "2117329216"
Server: Microsoft-IIS/7.5
X-Mod-H264-Streaming: version=2.2.7
X-Powered-By: ASP.NET
Date: Fri, 23 Aug 2013 21:20:34 GMT
On the second request, the GET headers are:
GET http://test/video.mp4 HTTP/1.1
Accept: */*
Accept-Language: en-GB
x-flash-version: 11,8,800,94
Accept-Encoding: gzip, deflate
If-Modified-Since: Wed, 21 Aug 2013 08:47:29 GMT
If-None-Match: "2117329216"
Connection: Keep-Alive
But in this case, I get the whole video downloaded rather than a 304 non modified response.
I noticed that X-Mod-H264-Streaming was used, not sure if this may have something to do with it.
Edit
I used the URL to the video in IE 10 directly (not using the flex application we were using before) and I get the same response where on the first request I get the complete video and after hitting f5 I get the whole video returned again rather than a 304 response.
I have an ASP.NET / MVC web app which when running locally produces this header:
Cache-Control:public, max-age=3
Connection:Close
Content-Encoding:gzip
Content-Length:287122
Content-Type:text/javascript
Date:Thu, 26 Jul 2012 21:21:26 GMT
ETag:K5fBpkMM+t9XPl07ydQ54pR6bg8=
Expires:Thu, 26 Jul 2012 21:21:29 GMT
Server:ASP.NET Development Server/10.0.0.0
X-AspNet-Version:4.0.30319
X-AspNetMvc-Version:3.0
But when running in AppHarbor behind their proxy the headers I get are these:
Cache-Control:public
Connection:keep-alive
Content-Encoding:gzip
Content-Length:287122
Content-Type:text/javascript
Date:Thu, 26 Jul 2012 21:22:49 GMT
ETag:K5fBpkMM+t9XPl07ydQ54pR6bg8=
Expires:Thu, 26 Jul 2012 21:22:41 GMT
Server:nginx
AppHarbor is stripping the Max-Age portion of my Cache-Control header and stomping over my Date with one I'm not synchronized with.
My goal is serve JavaScript via a CDN with a very short max age so that changes can be rolled out quickly. Changing the url frequently is not an option.
Does anyone know how to fix this?
A college who more closely examined the RFC noticed that it looks like the common one line form of this header used by servers and browsers:
Cache-Control: public, max-age=X
isn't actually valid. Splitting the two parts of the header into two lines like so:
Cache-Control: public
Cache-Control: max-age=X
works! So in my .net code, this:
response.Cache.SetCacheability(HttpCacheability.Public);
response.Cache.SetMaxAge(MaxAge);
becomes this:
response.AddHeader("Cache-Control", "public");
response.AddHeader("Cache-Control", "max-age=" + (int)MaxAge.TotalSeconds);
and now I can get a max-age out of AppHarbor.
I have a site hosted on a dedicated server (2008 R2 IIS7.5) and every so often I get a garbled web page similar to the ones below. The entire screen is filled with garbage. There seems to no pattern to the issue and it happens to others as well. I could go for hours, maybe days surfing the site without seeing it though. They are all .aspx pages on the site. Any ideas?
HTTP/1.1 200 OK Cache-Control: private Content-Type: text/html;
charset=utf-8 Content-Encoding: gzip Vary: Accept-Encoding Server:
Microsoft-IIS/7.5 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET
Date: Thu, 10 Mar 2011 17:48:59 GMT Content-Length: 9874 ? ????? ??
I?%&/m?{ J?J??t? ? $?# ????? iG#)?*??eVe]f #????{???{??;?N'????\fd
l??J??!??? ?~| ?"~??7N ??O?U????`#??P??????l9??T?L?????????C?7N?????? - snip -
HTTP/1.1 200 OK Cache-Control: private Content-Type: text/html;
charset=utf-8 Content-Encoding: gzip Vary: Accept-Encoding Server:
Microsoft-IIS/7.5 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET
Date: Mon, 28 Mar 2011 20:23:42 GMT Content-Length: 10601 ‹ í½
I–%&/mÊ{ JõJ×àt¡ € $Ø # ìÁˆÍæ’ì iG#)«* ÊeVe]f #Ìí ¼÷Þ{ï½÷Þ{ï½÷º;
N'÷ßÿ?\fd löÎJÚÉž!€ªÈ ?~| ?"~ãä7N ÿ®O¿^ämFãiWÛù/Z —Ÿ}tR-[j²ýæz•
”Nå¯Ï>jówí]À?L§ó¬nòö³¢©¶
î?ÜÞý(½{ô¸,–oÓ:/?û¨i¯Ë¼™çyûQ:¯óóÏ>ªó¦Z×Ó¼¹;mš»ôWÞŽé· Ò–zQàü÷"Ÿ A˜Öy¾|O
- snip-
Without inspecting the server I would not be able to tell you much, because a lot of times you would just look for idiosyncrasies or differences in configuration.
All I can say - for what is worth - is that there seems to be something to do with the GZIP (and not the encoding), considering this is a new feature in IIS. Both cases have GZIP turned on. Now it could be that you have turned the feature on but I suggest turning it off for a while to see if it happens again. This could be in fact a bug in IIS.
This has been bugging me for a while now. Whenever I try to share my website link on Facebook or another link-sharing site, the link-sharing site either removes the URL (like it doesn't recognize it as valid) or in Facebook's case - it can't retrieve meta-data automatically.
I'm pretty sure that it used to work. However, Googling / StackOverflowing for this problem is a difficult task, since I have no idea what possibly could create this problem.
I've tried to create a static .HTM file on my website, and that works fine:
test.htm
My default home page is a classic ASP (yeah I know, PHP version in the works) which uses IIS 7 URL Rewrite module.
I've tried to check the resultcodes and headers for both test.htm and my default home page on this page: http://gsitecrawler.com/tools/Server-Status.aspx
This is the results:
test.htm
URL=http://www.orango.nu/test.htm
Result code: 200 (OK / OK)
Content-Type: text/html
Last-Modified: Fri, 04 Feb 2011 10:16:55 GMT
Accept-Ranges: bytes
ETag: "0d877a654c4cb1:0"
Server: Microsoft-IIS/7.0
X-Powered-By: ASP.NET
Date: Fri, 04 Feb 2011 10:40:08 GMT
Content-Length: 452
default home page /
URL=http://www.orango.nu
Result code: 200 (OK / OK)
Cache-Control: public
Content-Length: 13463
Content-Type: text/html; Charset=UTF-8
Accept-Ranges: bytes
Server: Microsoft-IIS/7.0
Set-Cookie: ASPSESSIONIDSCSADCAR=DLPBECCBGDJMADLEPMOMHDDC; path=/
X-Powered-By: ASP.NET
Date: Fri, 04 Feb 2011 10:24:22 GMT
The first 4 lines of my default.asp (/) file are:
Response.ContentType = "text/html"
Response.AddHeader "Content-Type", "text/html;charset=UTF-8"
Response.CodePage = 65001
Response.CharSet = "UTF-8"
Does anyone have an idea what could be wrong and/or how to fix it? Any help or advice would be much appreciated, because this is driving me to the edge of madness.
The content-type looks wrong on your homepage...
HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 13463
Content-Type: text/html;charset=UTF-8,text/html; Charset=UTF-8
Server: Microsoft-IIS/7.0
X-Powered-By: ASP.NET
Date: Fri, 04 Feb 2011 10:48:39 GMT
I also don't see the need, at least for the homepage, for the cache-control: private header.