aspnetcore
aspnetcore copied to clipboard
Blazor - Accessing an API controller endpoint is triggering Routes.razor
Is there an existing issue for this?
- [X] I have searched the existing issues
Describe the bug
In an ASP.NET Core 8 Blazor web app, I have an API controller with the following setup. When the endpoint is accessed, for some reason, Routes.razor is being run (not sure if App.razor is being run prior to that).
Is this the intended behavior, either by default or with my configuration below, or possibly a bug?
MyController.cs
[ApiController]
[Route("api/[controller]")]
public class MyController : ControllerBase
{
[HttpGet]
public void MyMethod()
{
// code here
}
}
Here is the related information in Program.cs:
var builder = WebApplication.CreateBuilder(options);
builder.Services.AddControllers();
builder.Services.AddRazorPages().AddRazorRuntimeCompilation();
builder.Services.AddServerSideBlazor();
var app = builder.Build();
app.MapRazorComponents<App>().AddInteractiveServerRenderMode();
app.MapControllers();
Expected Behavior
When accessing an API endpoint, Blazor should not be involved.
Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version
8.0.204
Anything else?
No response