Reputation: 21023
I recently upgraded my project to .net-core 3.1 I noticed some bizarre behavior, all of my authenticated controllers 404.
I've left a default anonymous endpoint which I generally just use to verify that my api is working. This controller is working just fine.
[AllowAnonymous]
[Route("api/[controller]")]
public class ValuesController : Controller
{
//...
}
This controller seems to work fine, despite not being decorated with the [ApiController]
I've found a related issue which state that this is related to the ApiVersioning
However I don't see a way to set that in the startup in .Net-Core 3.1
I've added [ApiController]
to all of the authenticated controllers, the only affect I saw from this is that all of my Public Methods are now eligible to validations of the number of parameters allow to bind to the body. Everything still 404's
[ApiController]
[Route("api/[controller]")]
public class AccountController : Controller
{
//...
HttpPost("ExternalLogin")]
[AllowAnonymous]
public IActionResult ExternalLogin(string provider, string entryCode = null, string returnUrl = null)
{
//...
}
}
How can I get my controllers to receive the requests?
Upvotes: 1
Views: 619
Reputation: 3493
If you migrated from .NET Core 2.2 to 3.1, you will have to adjust Startup class:
In ConfigureServices:
Replace services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
with
services.AddControllers();
And in the Configure method:
Instead of
app.UseMvc();
Use:
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
Upvotes: 3