Description
Scenario.
I just upgraded a .netcoreapp2.2 Razor Pages web app (also containing some controllers annotated as [ApiController]
) to .netcoreapp3.3 using the docs at https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-2.2&tabs=visual-studio#update-routing-startup-code.
Afterwards, Javascript calls to the Api controllers started returning 404 until I included:
app.UseMvc()
in Configure method in Startup.cs which led to this warning message:
"Using 'UseMvc' to configure MVC is not supported while using Endpoint Routing. To continue using 'UseMvc', please set 'MvcOptions.EnableEndpointRouting = false' inside 'ConfigureServices'"
Everything worked fine after adding services.AddMvc(o => o.EnableEndpointRouting = false)
in ConfigureServices in Startup.cs.
Question
Shouldn't services.AddRazorPages()
provide out-of-the-box working support for Api controllers or accept an option config to enable it without the need to UseMvc()
?
What’s in AddRazorPages()
This updates in .NET Core 3.0 blog post by @danroth27 clearly mentions that AddRazorPages()
excludes some API-focused feautures:
https://devblogs.microsoft.com/aspnet/asp-net-core-updates-in-net-core-3-0-preview-4/