【问题标题】:Javascript content type being changed after URL RewriteURL 重写后更改的 Javascript 内容类型
【发布时间】:2017-06-28 17:49:25
【问题描述】:

我正在尝试使用 ARR 和 URL 重写进行反向代理以实现以下重定向:

显示的最终 URL 将与源 URL 相同。

重定向工作正常,但是在外部浏览时,我所有的 JavaScript 文件都被转换为 content-type text/html 而不是 application/javascript。这会导致空白页而不是实际功能。

重写规则:

<rules>
...
  <rule name="ReverseProxyInboundRule2" stopProcessing="true">
    <match url="^test(.*)" />
    <action type="Rewrite" url="http://{HTTP_HOST}:83/{R:1}" />
  </rule>
</rules>
<outboundRules>
  <rule name="ReverseProxyOutboundRule1" preCondition="IsJavascript">
    <match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" customTags="" pattern="^http(s)?://localhost:83/(.*)" />
    <action type="Rewrite" value="http{R:1}:{HTTP_HOST}/{R:2}" />
  </rule>
  <preConditions>
    <preCondition name="IsJavascript">
      <add input="{RESPONSE_CONTENT_TYPE}" pattern="^application/javascript" />
    </preCondition>
  </preConditions>      
</outboundRules>

目标页面使用 AJAX 功能,并且由于 js 文件被随机 html 标签损坏,导致 AJAX 功能失败。我该如何纠正这个问题?

【问题讨论】:

    标签: javascript asp.net iis reverse-proxy arr


    【解决方案1】:

    最后发现问题是由于目标应用程序中的相对路径造成的。代理后,js、css 和其他链接将重定向到自定义 404 错误页面,该页面是源应用程序的一部分。我已经通过修改代码解决了这个问题。

    【讨论】:

      猜你喜欢
      • 2016-12-07
      • 1970-01-01
      • 2013-11-27
      • 1970-01-01
      • 1970-01-01
      • 2014-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多