9

How do I remove the Vary:* from the response header for all my requests in the WEB APP (ASP.NET MVC)

Thanks

Sampat
  • 1,301
  • 6
  • 20
  • 34
  • 2
    This appears to be for an older version but does this help: https://stackoverflow.com/questions/9573501/how-to-supress-header-vary-when-using-outputcacheprofiles – PeterJ Jan 01 '18 at 03:56
  • Do you want to remove the Vary header so that it does not appear in the responses at all or do you only want to remove `Vary:*` so `Vary:Accept-Encoding `would be okay? – Harry Jan 02 '18 at 12:43
  • In ASP.NET Core, you can use [ResponseCacheAttribute](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.responsecacheattribute?view=aspnetcore-2.0), as explained in [this Microsoft article](https://learn.microsoft.com/en-us/aspnet/core/performance/caching/response). – Ruud Helderman Jan 07 '18 at 18:57

1 Answers1

0

The below code might help you.

protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
{
    HttpContext.Current.Response.Headers.Remove("Vary");
}

or in your web.config like:

<system.webServer> 
    <httpProtocol>
        <customHeaders> 
            <remove name="Vary" />
        </customHeaders> 
    </httpProtocol> 
</system.webServer>