IIS上的Angular 4/2应用程序托管

时间:2017-08-08 11:52:24

标签: angular web-hosting iis-10

我正在尝试在IIS 10上托管我的Angular 4应用程序,并且它正常工作 通过单击应用程序内的任何链接重定向到一个路由到另一个路由,但当我在URL中键入相同的链接时,我收到404错误消息。

我已经浏览过有角度的文档,它说我没有创建index.html的回退,我在IIS级别使用URL重写,但它没有工作。

我的托管应用程序网址为http://localhost:86/

以下是我的应用程序文件夹的结构,它在IIS中作为网站添加: enter image description here

基础href为<base href="/">

有什么不对吗?

还有一件事,是否使用此回退用户将无法输入url,因为它将重定向到index.html?

1 个答案:

答案 0 :(得分:0)

以下是在托管应用程序的webconfig中需要完成的任务。

<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="/" />
      </rule>
    </rules>
  </rewrite>
</system.webServer>

只需将其替换为web配置的内容,并考虑操作标记网址。我的基本网址是&#34; /&#34;。

谢谢