Dotnet core 3.1 global routing rule

86 Views Asked by At

I write a project in dotnet Core 3.1, and all my controllers have the same attribute

[Route("api/[controller]")]

I wonder if there is a way to white this rule somewhere on a global level, like Startup.cs

I searched in the microsoft documentation and couldn't find the answer.

1

There are 1 best solutions below

0
Farhad Zamani On BEST ANSWER

You can create a controller like this and all other controllers must be inherit form this controller

[Route("api/[controller]")]
public class ApiBaseController : ControllerBase
{

}

Another controllers should be like this

public class UsersController : ApiBaseController
{
}
public class OrderController : ApiBaseController
{
}