Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploy Blazor app to a IIS sub application

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.

like image 671
Smith5727 Avatar asked May 26 '20 16:05

Smith5727


People also ask

Is Blazor good for enterprise applications?

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.


1 Answers

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

like image 200
rk72 Avatar answered Sep 19 '22 17:09

rk72