Custom Cache-Control header for media files

GTEK IT DEV Team asked on January 24, 2019 08:30

Hi, i'm trying to custom the cache control header for my media files. But as i see, kentico cms added the Cache-Control header in to the response header. I'm try to remove it by the following code snippet in Application_BeginRequest function in global.ascx.cs file

if (context.Request.Path.ToLower().Contains("/getmedia/"))
{
    context.Response.Headers.Remove("Cache-Control");
    context.Response.Headers.Add("Cache-Control", "max-age=604800");
}

But i cannot see my value in the Cache-Control header. The value alwaysset as the default value from the CMS.

Correct Answer

Ryan Nguyen answered on January 24, 2019 12:16

You can try this in web.config

<location path="getmedia">
  <system.webServer>
      <httpProtocol>
          <customHeaders>
              <add name="Cache-Control" value="max-age=31536000" />
          </customHeaders>
      </httpProtocol>
  </system.webServer>

0 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.