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
/apiand the physical path tosite\api, with the type set asApplication.If your
.Browserproject does not have aweb.configfile, add it (you can use an example from this article). Then set<PublishIISAssets>true</PublishIISAssets>in the.csprojfile.Insert the following rule in your
web.configfile, to bypass/apicalls, 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
.Browserproject 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.
