Goal:
- Existing ASP.NET Web app with .NET SDK 7 created with individual users as authentication option on new project wizard.
- Add Blazor WebAssembly as SPA to be loaded on visiting a URL segment like {domain}/blazorApp
- Components of Blazor WebAssembly are not intended to be embedded into ASP.NET views or pages.
What have I tried till now
- Create a new project representing the "existing" ASP.NET Web app with .NET 7
- Add another project Blazor WebAssembly without the hosting or authentication options in new project wizard.
- Add reference to the Blazor project in the existing app
- Add
Microsoft.AspNetCore.Components.WebAssembly.Servernuget package to the existing project - Add
<StaticWebAssetBaseBath>clientapp</StaticWebAssetBaseBath>to Blazor csproj - In Blazor project > wwwroot > index.html add
<base href="/clientapp" />and prefix all the paths oflink hrefwith "clientapp" as the URL segment for WASM - Add below to the existing project > Program.cs
app.MapWhen(ctx => ctx.Request.Path.StartsWithSegments("/clientapp"), app1 =>
{
app1.UseBlazorFrameworkFiles("/clientapp");
app1.UseRouting();
app1.UseEndpoints(endpoints =>
{
//endpoints.MapControllers();
endpoints.MapFallbackToFile("/clientapp/{*path:nonfile}", "/clientapp/index.html");
});
//app1.UsePathBase("/clientapp");
app1.UseStaticFiles();
app1.UseStaticFiles("/clientapp");
});
- Also add
app.UseWebAssemblyDebugging();to the existing project > Program.cs
Issue
Getting HTTP 404 not found error on doing the above steps, running the project and navigating to /clientapp.