IIS内容类型错了COM pressed CSS [英] IIS content-type wrong for compressed CSS

查看:407
本文介绍了IIS内容类型错了COM pressed CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发主要使用的主题,但有一对夫妇在主题文件夹中CSS文件的ASP.NET站点的一部分。这些都是由像这样其他开发人员包含在web.config中:

I develop part of an ASP.NET site that uses mostly themes but has a couple of CSS files in the themes folder. These are included in the web.config by another developer like so:

<Content Include="App_Themes\SoftOrange\CMSStyles.css" />
<Content Include="App_Themes\SoftOrange\ContentStyles.css" />

在我们的内部测试服务器(IIS7,服务器2008 R2企业版),静态和动态融为一体pression全球IIS管理器中的选项上,超过2700个字节的文件。站点特定的静态和动态融为一体pression也启用。

On our internal test server (IIS7, Server 2008 R2 Enterprise) the global IIS manager options for static and dynamic compression are on, for files larger than 2700 bytes. The site-specific static and dynamic compression are also enabled.

在某些时候(大概在CMSStyles.css命中2700个字节)一些风格得到酿 - 即。明显不是通过查看页面加载。我发现,内容类型(根据火狐7.0.1)是显示文本​​/ CSS,当我装的URL,CMSStyles.css它看起来像在文本编辑器pssed垃圾正常COM $ P $

At some point (probably when CMSStyles.css hit 2700 bytes) some styles got stuffed - ie. were obviously not loading by looking at the page. I found that the content-type (according to firefox 7.0.1) was showing text/css, and when I loaded the URL for CMSStyles.css it looked like normal compressed junk in a text editor:

‹�����

等IE不直接打开c​​ss文件,但是当我使用的开发工具来显示CSS,它显示为空。

etc. IE doesn't directly open the css file, but when I use developer tools to show the css, it appears empty.

我关掉静态内容融为一体pression只是为了这个网站,和CSS文件,现在正常加载。我的问题是,为什么?它是一个内容类型的问题,内容编码,或者这是一个IIS的问题,或者与CSS在Web应用程序中使用的方式有问题?

I turned off static content compression just for this site, and the CSS files now load properly. My question is why?! Is it a content-type problem, Content-Encoding, or is this an IIS problem, or a problem with the way the CSS is used in the web app?

感谢。

编辑:

这些是为CMSStyles.css GET请求的标头:
响应头

These are the headers for the GET request for CMSStyles.css: Response Headers

Accept-Ranges  bytes
Content-Encoding    gzip
Content-Length  1728
Content-Type    text/css
Date    Fri, 13 Apr 2012 01:22:43 GMT
Etag    "80a762a82cecd1:0"
Last-Modified   Fri, 30 Mar 2012 04:22:03 GMT
Persistent-Auth true
Server  Microsoft-IIS/7.5
Vary    Accept-Encoding
X-Powered-By    ASP.NET

请求头

Accept text/css,*/*;q=0.1
Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
Accept-Encoding gzip, deflate
Accept-Language en-gb,en;q=0.5
Connection  keep-alive
Cookie  -removed-
Host    -removed-
Referer -removed-
User-Agent  Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1

所以它看起来像内容的编码是corrent:gzip的

so it looks like the content-encoding is corrent: gzip.

推荐答案

这里的问题(从我在类似问题的经验)是的Content-Length

The issue here (from my experiences in similar problems) is the Content-Length.

检查是否设置在code的任何部分的Content-Length ,删除它,它会重新工作。这是为什么 ?因为如果你设置了的Content-Length 在报头中的IIS则无法将其更改为COM pressed之一,使用gzip的DECOM preSS失败。为什么IIS无法改变它呢?因为默认情况下,如果你在IIS上设置一个头这个头依然存在,不能改变(特别是如果你提前进行冲洗)。还有,让IIS更改设置,但它只是为了更好地避免设置后的标志。

Check if you set the Content-Length in any part of your code, remove it and it will work again. Why is that ? because if you set the Content-Length on header the IIS then fail to change it to the compressed one, and the decompress of the gzip fails. Why IIS fail to change it ? because by default if you set a header on IIS this header remain and can not be change (especially if you flush it early). There is a flag that let IIS change it after you set it but its better just to avoid to set it.

类似的问题:
<一href=\"http://stackoverflow.com/questions/2582139/asp-net-site-sometimes-freezing-up-and-or-showing-odd-text-at-top-of-the-page-wh/2719080\">ASP.NET网站有时会凝固起来和/或显示在页面加载时的顶级奇文本,负载均衡的服务器上

从@thinkOfaN​​umber:原来的我使用devex preSS COM pression以及IIS COM pression 。我在web.config关闭devex preSS COM pression和它的作品!

From the @thinkOfaNumber : It turns out I was using devexpress compression as well as IIS compression. I turned off devexpress compression in the web.config and it works!

什么是在这里展示的是,第一个COM pression设置的Content-Length 和第二个COM pression无法改变它,因为的Content-Length 是标题和标题写不能改变*您​​已设置后,所以第二个COM pression改变最后的COM pressed侧结果是浏览器无法正确读出它,然后不DECOM preSS是正确的。

What is show here is that the first compression set the Content-Length and the second compression fail to change it because Content-Length is write on header and header can not change* after you have set it, so the second compression change the final compressed side with result that the browser fail to read it correct, and then fail to decompress it correct.

[*]有一种方法来改变标题后你送他们上IIS,在此之前将它们发送到浏览器,这可以通过更改IIS的默认行为可以做,但也不是那么容易,我做不知道是否可以解决这个问题。

[*] There is a way to change the headers after you have send them on IIS, and before send them to the browser, and this can be done with changing the default behavior of IIS but is not so easy and I do not know if can solve this issue.

这篇关于IIS内容类型错了COM pressed CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆