Angular 2 application not working when moved into IIS virtual directory

爷,独闯天下 提交于 2019-12-14 03:34:36

问题


I have created a Virtual Directory on IIS (inetmgr) on my local PC and later converted it into IIS Web Application. The web application's root is: http://localhost/xyz/ When deployed and ran the application, I get the following error in the browser:

All html components 404 not found errors.

Added rewrite rules in web.config. I changed index.html's base href to ./xyz or ./ but no luck.

If I deploy it to root directory, everything resolves - not sure what's going wrong.


回答1:


1. Enable xyz folder as a web application folder (See below picture)

2. Update base href, for example <base href="/spa/">

3. Set rewrite rule

<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" />
        <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
      </conditions>
      <action type="Rewrite" url="/" />
    </rule>
  </rules>

Hope it helps!



来源:https://stackoverflow.com/questions/43017193/angular-2-application-not-working-when-moved-into-iis-virtual-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!