OutputCache VaryByContentEncodings gzip doesn't work
Asked Answered
V

3

9

I've set the OutputCache to include 'VaryByContentEncodings="gzip"' in my ASP.net ASPX page. I want the page to serve different css files, a gzipped if the browser support it and the regular non compressed if the browser doesn't support compression.

Example:

<%@ OutputCache Duration="320" VaryByParam="none" VaryByContentEncodings="gzip"  %>   

When I run the code I get the following error:

The 'varybycontentencodings' attribute is not supported by the 'outputcache' directive in a page.

I don't know what's the problem and why it doesn't work. Second, do you think that by serving different gzip/non-compressed CSS I'm doing the right thing. Just note that the files are served from Amazon S3, so I can't rely on IIS or .NET engine to return the compressed files automatically. That's why I want to serve to separate cached version of the page.

In this it seems to be ok, but it doesn't work (using ASP.NET 4.5):

http://msdn.microsoft.com/en-us/library/system.web.httpcachevarybycontentencodings.aspx

Help would be greatly appreciated.

Verlaverlee answered 7/10, 2011 at 17:57 Comment(0)
V
6

Funny mistake, I've just forgot to put the Location attribute and therefore I've got an error. However, Microsoft put this code on their website, and that lead me to think that this code should work AS IS.

http://msdn.microsoft.com/en-us/library/system.web.httpcachepolicy.varybycontentencodings.aspx

Verlaverlee answered 17/2, 2013 at 14:20 Comment(0)
S
4
  • What version is your app pool running?
  • Is the directive in a page, control or masterpage?

VaryByContentEncodings is introduced in the .NET Framework version 3.5.

HttpCachePolicy.VaryByContentEncodings Property

Studley answered 7/10, 2011 at 18:13 Comment(0)
S
1

I just had exactly the same problem. The problem is - Visual Studio intellisense suggests you an incorrect attribute name. The correct one, is "VaryByContentEncoding" - withough the "s" in the end.

Correct:

<%@ OutputCache ... VaryByContentEncoding="gzip"  %>

Incorrect:

<%@ OutputCache ... VaryByContentEncodings="gzip"  %>
Seriocomic answered 29/10, 2015 at 19:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.