Search code examples
asp.net-web-api-routing.net-6.0

API Controller Routing in .NET 6 Doesn't Work Any More


I'm trying to create a standard WebAPI project in .NET 6. I notice that the standard ApiController route doesn't have the leading api route that I like to have. When I add it, the controller breaks. It doesn't give me a 404 (not found), it just gives me that index page that says that I have to enable javascript. I'm really at a loss at what I have to do to make my app work where I can put api at the start of my routes: [Route("api/[controller]")]

I've tried adding it to the default controller route map in different combinations. I've tried adding the UseEndpoints method in the Program class. I'm just not sure what to differently in 6.

For those who want to "see my code", I'm just using the standard WebAPI project w/ React (NO Redux!).


Solution

  • Check the new setupProxy.js file image description inside the ClientApp folder, you need to configure the backend routes in the proxy config, I had a similar issue with the ASP.NET Core 6.0 with Angular project template, you can find more information here link 1 link 2