Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

How to add Blazor Webassembly to an existing ASP.NET Core web app with .NET 7?

$
0
0

Goal:

  1. Existing ASP.NET Web app with .NET SDK 7 created with individual users as authentication option on new project wizard.
  2. Add Blazor WebAssembly as SPA to be loaded on visiting a URL segment like {domain}/blazorApp
  3. Components of Blazor WebAssembly are not intended to be embedded into ASP.NET views or pages.

What have I tried till now

  1. Create a new project representing the "existing" ASP.NET Web app with .NET 7
  2. Add another project Blazor WebAssembly without the hosting or authentication options in new project wizard.
  3. Add reference to the Blazor project in the existing app
  4. Add Microsoft.AspNetCore.Components.WebAssembly.Server nuget package to the existing project
  5. Add <StaticWebAssetBaseBath>clientapp</StaticWebAssetBaseBath> to Blazor csproj
  6. In Blazor project > wwwroot > index.html add <base href="/clientapp" /> and prefix all the paths of link href with "clientapp" as the URL segment for WASM
  7. 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");});
  1. Also add app.UseWebAssemblyDebugging(); to the existing project > Program.cs

Source code on GitHub

Issue

Getting HTTP 404 not found error on doing the above steps, running the project and navigating to /clientapp.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>