开发者

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' attrib开发者_开发技巧ute 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.


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


  • 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


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"  %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜