【问题标题】:Angular 5 : Deploy app to IIS under nested folderAngular 5:将应用程序部署到嵌套文件夹下的 IIS
【发布时间】:2018-08-06 11:32:21
【问题描述】:

我正在使用 Angular 5.2 并部署在我的 localhost IIS 服务器 中,它工作正常。

我的本​​地主机 URL 如下所示:- http://localhost/DEV

DEV 是我的本地 IIS 服务器中的虚拟目录。上述 URL 一切正常。

现在我想在 DEV 中添加另一个嵌套 VD 作为 childApp。 我希望我的应用以 http://localhost/DEV/childApp 的身份运行。

所以我将 index.html 内容更改为具有这样的基本 href :-

<base href="/DEV/childApp/">

并且还将 URL 重写规则的 web.config 文件更新为:-

来自

<action type="Rewrite" url="./index.html" />

到

<action type="Rewrite" url="/DEV/childApp/" />

Web.config 看起来像这样:-

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Angular Routes" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
           <action type="Rewrite" url="/DEV/childApp/" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

但它给我的错误是:-

HTTP 错误 500.52 - URL 重写模块错误。无法添加类型为“规则”且唯一键属性“名称”设置为“角度路线”的重复集合条目

请建议如何修复 web.config 以进行 URL 重写或其他地方。

【问题讨论】:

  • 这是不同的,它与 Angular 应用程序及其基础 href 有关。
  • 如果这是您遇到的错误,则不会。这不是 Angular 错误,而是 IIS 错误。您是否添加了&lt;clear /&gt; 作为答案?
  • 感谢 Daniel W Strimpel

标签: angular iis url-rewriting angular5 angular-routing


【解决方案1】:

将&lt;clear /&gt; 添加到web.config 是解决方案。

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
       <clear /> <!--Imperative Step, otherwise IIS will throw err-->
        <rule name="Angular Routes" stopProcessing="true">
          <match url=".*" />
          ............
          ..........

【讨论】:

    猜你喜欢
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-19
    • 2019-12-04
    • 1970-01-01
    • 1970-01-01
    • 2020-07-25
    相关资源
    最近更新 更多