URL 重写后 Javascript 内容类型被更改

标签 javascript asp.net iis reverse-proxy arr

我正在尝试使用 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 功能失败。我该如何纠正这个问题?

最佳答案

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

关于URL 重写后 Javascript 内容类型被更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44809417/

相关文章:

javascript - Jquery - 将点击事件绑定(bind)到变量

Javascript 获取大括号内的子字符串值

c# - 错误 : "Cannot implicitly convert type"

c# - 具有多个创建 FTP 请求的线程的 ThreadPool 超时

iis - 在 Windows XP 上将 IIS 5.1 升级到 IIS 6

php - 我如何在 Mootools 中通过 AJAX 发送的数据中转义 '+'?

asp.net - ASP .Net Core 2.2 发布到 Azure

asp.net - 无需模拟的 IIS 7.5 集成身份验证 NTFS 文件夹权限

asp.net - 为什么从iis调用XMLRPC时fiddler没有捕获请求?

javascript - jQuery,可选和文本对齐属性问题