Angular 5:将应用程序部署到IIS的嵌套文件夹下

4

我正在使用Angular 5.2并在我的本地IIS服务器上部署,一切都运行良好。

我的本地URL看起来像这样:- http://localhost/DEV

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

现在我想在DEV下添加另一个嵌套的子VD作为childApp。

我希望我的应用程序以http://localhost/DEV/childApp的方式工作。

所以我更改了index.html内容,加入了base href:

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

并且我已经更新了web.config文件,使URL重写规则为:

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

TO

<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 Rewrite模块错误。无法添加具有唯一密钥属性“名称”设置为“Angular Routes”的类型“规则”的重复集合条目

请建议如何修复web.config中的URL重写或其他位置。


可能是Web应用程序中的URL重写错误的重复问题。 - Daniel W Strimpel
这是不同的,与Angular应用程序及其基本href有关。 - Karan
1
不是你遇到的错误。那不是Angular错误,而是IIS错误。你是否像答案中所说的添加了<clear /> - Daniel W Strimpel
感谢Daniel W Strimpel。 - Karan
1个回答

2
在web.config中添加<clear />是解决方案。
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
       <clear /> <!--Imperative Step, otherwise IIS will throw err-->
        <rule name="Angular Routes" stopProcessing="true">
          <match url=".*" />
          ............
          ..........

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接