Search code examples
c#.net-coreblazorasp.net-core-mvcblazor-server-side

Blazor server on ASP.NET Core MVC getting error 500 when loading blazor.server.js [.NET8]


I'm testing this Blazor server on our existing ASP.NET Core MVC project using the latest .NET 8.

When running, this error always occurs:

The request matched multiple endpoints. Matches: Blazor static files

enter image description here

I followed the tutorial at Microsoft:

services.AddRazorComponents().AddInteractiveServerComponents();

app.UseStaticFiles();
  //blazor
  app.MapBlazorHub();
  app.MapRazorComponents<App>().AddInteractiveServerRenderMode();

When removing AddInteractiveServerRenderMode() in MapRazorComponents, the blazor.js file is loading but onclick trigger event is not working


Solution

  • In Net7 and below you use app.MapBlazorHub() to configure the Blazor Server HTTP request pipeline.

    In Net8 [with it's render modes] .AddInteractiveServerRenderMode() configures the HTTP request pipeline to support the specific render mode.

    You can't do both.

    Note: .AddInteractiveServerComponents() configures the necessary services for the specific render mode.