Wednesday, March 16, 2011

How do you change the http header information sent in IIS 6

Currently IIS sends an expires http header of yesterday minus 1 hour on ASP.NET pages. How do I change this to 60 seconds in the further instead?

From stackoverflow
  • Go to IIS administration -> -> Properties -> HTTP Headers tab -> click Enable Content Expiration, and set it to whatever you want.

    Frederik Vig : I enabled content expiration and set expires after to 10 days, but still get the same result (yesterday minus one hour). I also checked the time on the server and it is the current time and date.
    AviD : Just occurred to me, is this for HTTPS pages? ASP.NET by default forces immediate expiration for "secured" pages, the thinking being if it requires transport security it shouldnt be cached either.
    Frederik Vig : Unfortunately no, it's normal HTTP pages.
    AviD : Then you may need to do a little debugging. Where is the expiration coming from - header or meta? Added by IIS, ASP.NET, or ASPX page code? What does it look like, might there be two conflicting instructions?
    Frederik Vig : Found it, IIS diden't work and neither did META tags. But setting it programmaticly in my code-behind did the trick :).
    AnthonyWJones : Content Expiration headers apply to static content. It is assumed that dynamic content will set whatever headers are required.
  • You can also add a content-expires page directive to your ASP.NET page (for different expire schedules):

    @Outputcache

    Or you can set the header inside your code (perhaps a base page class):

    Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));

    A good article on caching can be found on MSDN:

    http://support.microsoft.com/?scid=kb%3Ben-us%3B323290&x=11&y=6

0 comments:

Post a Comment