I'm trying to include a blazor component into my MVC application, but something with the endpoint routing does not seem okay.
I have a razor page (in pages/example.cshtml) and a default controller (in Controllers/Home) with views (in Views/Home/Index.cshtml).
Opening...
- [local] -> index view, Blazor works
- [local]/Home -> index view, Blazor works
- [local]/Example -> example page, Blazor works
- [local]/Home/ -> index view, Blazor DOES NOT work
- [local]/Home/Index -> index view, Blazor DOES NOT work
The script debugger says: HTTP404: NOT FOUND - The server has not found anything matching the requested URI (Uniform Resource Identifier). (XHR)POST - https://localhost:44342/Home/_blazor/negotiate
I tried different things in the startup file, but whatever I tried I wasn't able to make it work.
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddSingleton<WeatherForecastService>();
//services.AddControllersWithViews(o => o.EnableEndpointRouting = false); -> does not change anything
services.AddMvc(o => o.EnableEndpointRouting = false);
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseMvcWithDefaultRoute();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapBlazorHub();
//endpoints.MapControllers(); -> does not change anything
//endpoints.MapDefaultControllerRoute(); -> does not change anything
});
}
}