Vary: * incorrectly added to http header response (asp.net mvc3)
Asked Answered
J

2

8

I am using the following output cache profile:

<add name="MyFunkyProfile" duration="180" varyByParam="*" location="ServerAndClient" />

In dev, I have a response header with one Vary entry:

HTTP/1.1 200 OK
Server: Microsoft-IIS/7.5
...
Vary: Accept-Encoding
Cache-Control: private, max-age=180, s-maxage=0
...

When I deploy my app, I have an extra Vary entry inserted in the response:

HTTP/1.1 200 OK
Server: nginx
...
Vary: Accept-Encoding
Cache-Control: private, max-age=180, s-maxage=0
...
Vary: *
...

Why this extra Vary entry? This is preventing the cache from working correctly.

Any ideas how to fix this?

Jeopardous answered 3/8, 2012 at 12:8 Comment(0)
C
0

Have you tried setting varyByParam to None in your profile/config file? See http://msdn.microsoft.com/en-us/library/hdxfb6cy.aspx.

Also, just guessing here - does the config file differ between dev and 'live', e.g. varyByParam may be set differently?

Note: I've just joined SO so can't add comments just yet (which I would have done instead of posting this as a reply).

Cosette answered 6/8, 2012 at 11:16 Comment(1)
Can't set varyByParam to None this will yield wrong results. No the varyByParam is set in the same way in dev and prod. The server is different though; dev server vs IIS.Jeopardous
D
0

The Vary: Accept-Encoding header is inserted by the AppHarbor routing layer. The header is necessary to get downstream proxies (typically a CDN like AWS CloudFront or similar) to correctly cache both gzip'ed and non-gzip'ed versions of your content. This question has additional details.

Can you detail how this is causing problems for your application?

Dinger answered 6/8, 2012 at 21:40 Comment(1)
Vary star is inserted by the framework by default unless varyByParam="" is specified (notice that varyByParam="*" still generates vary star) see Atwood's answer here https://mcmap.net/q/583571/-expire-output-cache-asp-net-mvc . Worked around the problem. Will post the workaround here as answer.Jeopardous

© 2022 - 2024 — McMap. All rights reserved.