I have two projects that need to be published together on the same IIS site.
One of the projects is an Angular application, and the other is an ASP.NET Core Web API.
For various reasons, the Web API project must be the “main” one, even though it only serves requests to /api
.
I thought about publishing the Angular project in an app folder, but I need requests to http://mysite/home
, for example, to be handled by the Angular routes. Unfortunately, I can’t use http://mysite/app/home
.
A partial solution I found was to use URL rewriting in the following way, but I still haven’t achieved the desired behavior, mainly due to the redirection to index.html
(which shouldn’t appear in the URL, obviously).
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to app folder if exists" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_URI}" pattern="^/api" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" pattern="^app/{R:1}$" />
</conditions>
<action type="Rewrite" url="/app/{R:1}" />
</rule>
<rule name="Redirect to index.html if not found in app" 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" />
<action type="Rewrite" url="/index.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>