I am trying to deploy my Blazor Server application under /app which is a sub application in IIS. I read on several places online that I need to set the following:
Startup.cs | app.UsePathBase("/app")
and
_Host.cshtml | <base href="~/app/" />
But when I run this I get the following error:
blazor.server.js:15 [2020-05-26T16:16:11.796Z] Error: The circuit failed to initialize.
e.log @ blazor.server.js:15
blazor.server.js:1 [2020-05-26T16:16:11.798Z] Information: Connection disconnected.
blazor.server.js:1 Uncaught (in promise) Error: Invocation canceled due to the underlying connection being closed.
at e.connectionClosed (blazor.server.js:1)
at e.connection.onclose (blazor.server.js:1)
at e.stopConnection (blazor.server.js:1)
at e.transport.onclose (blazor.server.js:1)
at e.close (blazor.server.js:1)
at e.stop (blazor.server.js:1)
at e.<anonymous> (blazor.server.js:1)
at blazor.server.js:1
at Object.next (blazor.server.js:1)
at a (blazor.server.js:1)
If I change to (without trailing slash)
_Host.cshtml | <base href="~/app" />
The application runs but without any /app before the URL (no change as far as I can see).
On some example I saw that they changed the BlazorHub path but I just cannot get it to work. The reason behind this is to be able to host application and landing page as separate IIS sites.
Blazor offers promising new tools for building rich web interfaces with C#. This course, Designing and Building Enterprise Blazor Applications, will explore important architectural topics like dependency injection and routing in-depth.
This works for us:
<base href="/app/" />
Note the trailing slash, it is important.
It is documented in the official Blazor docs here: https://docs.microsoft.com/en-us/aspnet/core/blazor/host-and-deploy/?view=aspnetcore-3.1&tabs=visual-studio#app-base-path
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With