Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OutputCache VaryByContentEncodings gzip doesn't work

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.

like image 370
Idan Shechter Avatar asked Oct 07 '11 17:10

Idan Shechter


3 Answers

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

like image 91
Idan Shechter Avatar answered Sep 25 '22 14:09

Idan Shechter


  • 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

like image 39
rick schott Avatar answered Sep 21 '22 14:09

rick schott


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"  %>
like image 31
Dmitry Dzygin Avatar answered Sep 25 '22 14:09

Dmitry Dzygin