Hosting both OpenSilver app and its backend on a single Azure Web App
This guide demonstrates how to deploy an OpenSilver app to the root and the server to a sub-path, such as /api
, on the same Azure Web App.
In the Azure Web App settings, add a virtual directory for the backend. For example, set the virtual path to
/api
and the physical path tosite\api
, with the type set asApplication
.If your
.Browser
project does not have aweb.config
file, add it (you can use an example from this article). Then set<PublishIISAssets>true</PublishIISAssets>
in the.csproj
file.Insert the following rule in your
web.config
file, to bypass/api
calls, allowing them to be handled by the backend app:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="API Rule" stopProcessing="true">
<match url="api/(.*)" />
<action type="None" />
</rule>
<!--Other rules-->
</rules>
</rewrite>
</system.webServer>
</configuration>
- Ensure you updated the server URL in the client app to
https://your-site-name.azurewebsites.net/api/
. - Publish the
.Browser
project from Visual Studio using the publish profile that you can get on the Azure portal. - Publish the backend project by importing the same publish profile, but modify the Site name to
your-site-name/api
.