1

I have web page that uses no-cache mechanism for not to let browser to cache content. However, I have some doubts. The developer has inserted no cache code into the PageLoad method in MasterPage.

It is like this (on Page Load in Master Page)

   HttpContext.Current.Response.CacheControl = "no-cache"
   HttpContext.Current.Response.AddHeader("Pragma", "no-cache")
   HttpContext.Current.Response.ExpiresAbsolute = DateTime.Now.Date
   HttpContext.Current.Response.Expires = -1

I have some doubt that this is the correct action and whether this could should be better inserted into BasePage OnInit event?

Arun Bertil
  • 4,598
  • 4
  • 33
  • 59
renathy
  • 5,125
  • 20
  • 85
  • 149

1 Answers1

2

You could do this HTTPHeaders before you generate the response. Check MSDN

Page_init/page_load or MasterPage/BasePage/ActualPage

Refer Disabling browser caching for all browsers from ASP.NET

Also you could do this in page directive

<%@ OutputCache Duration="60" VaryByParam="None"%>

Even in Web.config you can configure

<caching>
  <outputCacheSettings>
    <outputCacheProfiles>
      <add name="Cache30Seconds" duration="30" 
        varyByParam="none" />
    </outputCacheProfiles>
  </outputCacheSettings>
</caching>

More Information on Caching

Community
  • 1
  • 1
Murali Murugesan
  • 22,423
  • 17
  • 73
  • 120