【问题标题】:Outbound rules don't apply inside updatepanel出站规则不适用于更新面板
【发布时间】:2013-03-15 23:48:10
【问题描述】:

TLDR:出站规则不适用于更新面板部分回发


我正在使用 IIS 7.5 URL 重写器将图像路径映射到 cdn。

这是正在发生的事情的简化版本

<Repeater Goes Here>

    <img alt="alt text" src="<%#getImageSource(Eval("Filename").ToString() )%>">

<End of Repeater>

假设函数 getImageSource 返回"/images/someimage.jpg"

这又重写为

<img alt="alt text" src="http://img.cdn.com/someimage.jpg">

使这项工作的出站规则是:

    <rule name="Out_Rewrite_ServeCookieLessImages" preCondition="ResponseIsHtml" enabled="true">
      <match filterByTags="Img" pattern="^/Images/(.*)$"/>
      <action type="Rewrite" value="http://img.cdn.com/{R:1}"/>
    </rule>

    <preConditions>
      <preCondition name="ResponseIsHtml">
        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html"/>
        <add input="{URL}" pattern="\.axd.*$" negate="true"/>
      </preCondition>
    </preConditions>

问题是在更新面板中使用中继器时

异步回发后输出的实际 html 是

<img alt="alt text" src="/Images/someimage.jpg">

而不是

<img alt="alt text" src="http://img.cdn.com/someimage.jpg">

如何让更新面板正确解析输出?

提前致谢


编辑:我现在的猜测是它必须对页面生命周期做一些事情......或者也许调用重写模块的顺序......将保持更新

【问题讨论】:

    标签: c# asp.net iis-7.5 updatepanel url-rewrite-module


    【解决方案1】:

    使用 UpdatePanel 时服务器返回的响应内容类型是 text/plain 而不是 text/html。

    您列出的 ResponseIsHtml 前提条件将仅匹配 text/html 内容,这就是不重写 UpdatePanel 响应的原因。

    如果您修改输入正则表达式以捕获文本/纯文本,那么您的内容将被重写:

    <preConditions>
      <preCondition name="ResponseIsHtml">
        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/[html|plain]"/>
        <add input="{URL}" pattern="\.axd.*$" negate="true"/>
      </preCondition>
    </preConditions>
    

    不幸的是,这样做有一个问题,我还没有找到解决方案 - 重写响应会导致 UpdatePanel ajax 管理器抛出 ys.WebForms.PageRequestManagerParserErrorException。

    【讨论】:

      猜你喜欢
      • 2012-05-24
      • 2023-03-23
      • 1970-01-01
      • 1970-01-01
      • 2017-03-16
      • 2011-06-18
      • 1970-01-01
      • 1970-01-01
      • 2021-09-10
      相关资源
      最近更新 更多