IIS7:由于URL重写和OutboundRules使用导致内容长度不匹配

时间:2013-06-13 22:14:41

标签: caching iis-7 url-rewriting web-config outbound

我在将配置的出站规则配置为在IIS7上运行时遇到了一些问题,这是让我感到悲伤的场景。我的最终目标是让任何outboundRules在几个浏览器中运行。对于此示例,我正在使用从各种HTML标记中删除.aspx的规则。

场景1(内容长度不匹配):

要使该特定规则在IIS7中工作,我必须禁用动态压缩并默认关闭缓存。我成功地重写了HTML,但是出现了另一个问题,使得这个问题无法使用。

当尝试使用outboundrules重写内容时,我遇到了一个问题,Chrome和Firefox由于标题中的“内容长度不匹配”而执行连续加载(感谢Fiddler帮助我识别它)。重写有效,但它导致内容长度不正确,因此这两个浏览器看起来像是永远加载。特别是Chrome导致了一个问题,因为javascript似乎已挂起,因此任何jquery都无法正常工作,直到某人实际点击停止按钮。

这是我开始的web.config的相关部分,以便给我这个场景:

<system.webServer>
  <rewrite>
    <urlCompression doStaticCompression="false" doDynamicCompression="false" dynamicCompressionBeforeCache="false" />
    <modules runAllManagedModulesForAllRequests="true" />
    <outboundRules>
      <rule name="Remove .aspx from links in the response" preCondition="IsHTML" stopProcessing="false">
        <match filterByTags="A, Area, Base, Form, Frame, IFrame, Link, Img, Script" pattern="(.*)\.aspx(\?.*)?$" />
        <action type="Rewrite" value="{R:1}{R:2}" />
      </rule>
      <preConditions>
        <preCondition name="IsHTML">
          <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
        </preCondition>
      </preConditions>
    </outboundRules>
  </rewrite>
  <caching enabled="false" enableKernelCache="false" />
</system.webServer>

在研究这个问题时,我发现这个stackedoverflow question提到了outboundRules标记上的 rewriteBeforeCache =“true”属性以及这个blog post。我遇到内容长度问题的事情。

如果我修改了该属性,则会导致我的“出站规则”无法继续工作。

方案2(出站规则不起作用):

因此,由于先前的信息,我开始调整web.config并且能够通过在outboundRules标记上使用rewriteBeforeCache属性来解决内容长度不匹配问题。为了使该属性起作用,我能够重新开启缓存。这解决了方案1中的响应长度不匹配问题,但现在没有任何outboundRules \ rule元素可以正常工作。我已经尝试了许多最简单的规则,当我删除rewriteBeforeCache属性时它们运行正常,但这会导致场景1:

<system.webServer>
  <rewrite>
    <urlCompression doStaticCompression="false" doDynamicCompression="true" dynamicCompressionBeforeCache="false" />
    <modules runAllManagedModulesForAllRequests="true" />
    <outboundRules rewriteBeforeCache="true">
      <rule name="Remove .aspx from links in the response" preCondition="IsHTML" stopProcessing="false">
        <match filterByTags="A, Area, Base, Form, Frame, IFrame, Link, Img, Script" pattern="(.*)\.aspx(\?.*)?$" />
        <action type="Rewrite" value="{R:1}{R:2}" />
      </rule>
      <preConditions>
        <preCondition name="IsHTML">
          <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
        </preCondition>
      </preConditions>
    </outboundRules>
  </rewrite>
</system.webServer>

方案1导致IIS7中的浏览器出现一个错误;场景2导致outboundrules停止工作。

我修改了任意数量的选项,禁用了缓存,块模式传输,并尝试了我能想到的每个组合。

AppPool上的其他说明:IIS7,.NET4.0,经典管道

除了迁移到IIS7.5服务器之外,还有其他人对我有什么其他选择可以解决这个问题吗?

0 个答案:

没有答案