I have successfully add a Blazor WebAssembly app to an existing ASP.NET Core app. You can check the demo repository here on GitHub. I also wrote the detailed step-by-step instruction there.

Step-by-step guide
1. Setup a new Blazor WebAssembly App (B)
Create a new Blazor WebAssembly App
project, for example DemoBlazorInsideWeb.BlazorApp
.
Update your router in App.razor
to show the Index
page for all routes:
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<!-- Delete everything here -->
</Found>
<NotFound>
<!-- Add this here -->
<LayoutView Layout="@typeof(MainLayout)">
<Index />
</LayoutView>
</NotFound>
</Router>
Optionally delete @page
in your Index.razor
file so no URL can ever be routed to it. This is to prevent a route accidentally match it.
Optionally delete index.html
file in your wwwroot
folder. However you may want to keep the content somewhere to copy its content later.
Note
You can still use Routing if you want to serve multiple apps on the same website (even though you have to pack all those apps inside this single project)
2. Setup your (existing) ASP.NET Core website (A)
dotnet add package Microsoft.AspNetCore.Components.WebAssembly.Server
- In your app startup (
Program.cs
or Startup.cs
), add app.UseBlazorFrameworkFiles()
before app.UseStaticFiles()
:
app.UseBlazorFrameworkFiles();
app.UseStaticFiles();
3. Setup the new web (Feature) page
In the ASP.NET Core Razor Page that you want to add the Blazor app, you need to setup Blazor's content
- Add the HTML and Javascript content:
<!-- Other Razor code -->
<div id="app">
<!-- Loading content before Blazor loads. You can copy it from index.html file -->
</div>
<div id="blazor-error-ui">
An unhandled error has occurred.
<a href="" class="reload">Reload</a>
<a class="dismiss"></a>
</div>
<!-- Other Razor code -->
<!-- Add the script where relevant to your project -->
<script src="_framework/blazor.webassembly.js"></script>
- You should also refer to the Blazor's CSS file, or simply move its content to your own ASP.NET Core project:
<!-- You need to have Heads section in your Layout -->
@section Heads {
<link rel="stylesheet" href="~/css/app.css" />
}