I have to create a routing logic for a .Net Core 3.0 Web API project that routes to different controllers with same route prefix given a value.
Example: I have controllers based on states.
StateUsersCOController
StateUsersCAController
StateUsersWAController
and such.
They all implement the same method such as:
GetUsers();
What I want to achieve is my request routed to a related controller based on state information such as:
api/StateUsers/CA
or
api/StateUsers?state=CA
or
api/StateUsers and Request Header has the state Information such as State:CA
What I can come up is creating a controller called StateUsers, capture the state value in one of the provided ways mentioned above and redirect the request to related controller, but I want to avoid redirection and achieve this is routing level. Can you guys please provide a better way to do this.