user2385776
user2385776

Reputation: 21

Angular 2 application not working when moved into IIS virtual directory

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.

Upvotes: 0

Views: 1860

Answers (1)

KarateJB
KarateJB

Reputation: 961

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!

Upvotes: 1

Related Questions