[ACCEPTED]-Cache-Control Headers in ASP.NET-header

Accepted answer
Score: 23

You might also want to add this line if 14 you are setting the max age that far out 13 :

// Summary:
// Sets Cache-Control: public to specify that the response is cacheable
// by clients and shared (proxy) caches.    

I do a lot of response header manip with 12 documents and images from a file handler 11 that processes requests for files the are 10 saved in the DB.

Depending on your goal 9 you can really force the browsers the cache 8 almost all of you page for days locally 7 ( if thats what u want/need ).


I also 6 think you might be setting the max age wrong...

Response.Cache.SetMaxAge(new TimeSpan(dt.Ticks - DateTime.Now.Ticks ));

this 5 line set is to 30 min cache time on the 4 local browser [max-age=1800]

As for the 2x 3 Cache Control lines... you might want to 2 check to see if IIS has been set to add 1 the header automatically.

Score: 12

I don't see Cache-control appearing twice. One 12 is in the request, one is in the response. The 11 one in the request is probably because you 10 hit Shift+F5 in the browser or something 9 similar.

To your second question: that depends 8 on what you want to achieve with the cache 7 headers.

I don't know what you wanted to 6 achieve with the max-age. The value is way 5 too high since you converted the DateTime 4 incorrectly to a TimeSpan. Why don't you 3 just use TimeSpan.FromMinutes instead?

Page 2 load is okay. I usually mess around with 1 HTTP headers there myself.

More Related questions