I have found a similar question that relates to standard asp.net controllers, but i have tried it and it doesn't seem to be working with the apicontroller.
Restrict route to controller namespace in ASP.NET Core
I want to allow for an API to be deprecated in the future without needing to change the url. To solve this i will put a version prefix at the start of the route. This way i can add some modifications to an endpoint without breaking any integrations with this API.
config.Routes.MapHttpRoute(
name: "V1 API",
routeTemplate: "v1/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "V2 API",
routeTemplate: "v2/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
I want to keep the same controller names and in most cases everything will be the exact same, the response and request body will be the only things that change. I have tried to add a subdirectory in the controllers folder in order to add v1 and v2 to the namespace of the controller, but i get an error about there being 2 controllers having the same name.
How can i modify the routes so that it will point to the v1 namespace for the controller instead of just searching for any class within the controller. I dont want to have to add the version to the controller name as i want to make the revision updates as seamless as possible.