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>
For various reasons, the Web API project must be the "main" one,? I strongly suspect creating a web application in a folder at/apiin your webroot and leaving your static site in the root would simplify things and work fine. IIS has features like<Location />blocks in web.config or even installing ARR (Application Request Routing) to allow for more elaborate setups but your case seems simple(unless am i missing something?). Can you expand your question? Please add errors from browser or Windows Event Log, or IIS HTTPERR log.SpaControllerwith[Route("{*path}", order = 5)]- the order=5 means it's applied last, if there are no other routes defined, and that controller serves an HTML page that hosts the SPA, and aApiControllerwith[Route("api")]which is where the API is. TheApiControlleris more or less just a facade for elements in an API project in same solution. YMMV.