pm100
pm100

Reputation: 50190

How to convert a Blazor WASM standalone app to a hosted one

I have a large working Blazor WASM app. When I started I thought I wanted a free standing one. Now I realize I should have select hosted - ie have it served by a separate asp.net web server. In order to see how that client seever combo should work I have created a test app in that configuration and cannot work out how it works.

The Web server BlazorApp1.Server is serving files from the wwwroot of the BlazorApp1.Client. But I dont see how it is getting to those files. I looked at the EnvironMent.WebRoot of the server and its not set, its ContentRoot points to itself

Apart from the webroot issue are there any other changes I would need to make. I looked at the project templates and could not see any obvious ones

Upvotes: 1

Views: 2313

Answers (1)

Henk Holterman
Henk Holterman

Reputation: 273449

As far as I know there are no differences in the Client project between Hosted and Standalone.

In the Hosted setup, in your Server the key points are:

  • The Server project has a Project Reference to the Client
  • The Program.cs should have app.UseBlazorFrameworkFiles();
    and app.MapFallbackToFile("index.html");

I would create a new Hosted project and drop in the original Client project, fix the names (and namespaces) and link the Server to the right Client.


plus need to add nuget packages

  • microsoft.aspnetcore.components.webassembly //- microsoft.aspnetcore.components.webassembly.devserver
  • microsoft.aspnetcore.components.webassembly.server

I also added app.UseStaticFiles

Actually no, dont add devserver to the Server app. You want Server in the server app and devserver in the client

DevServer is a minimal kestrel server hard coded to nice defaults just for booting up a blazor wasm client. It also supports the debugging of the client c# code.

Upvotes: 1

Related Questions