0
 config.Routes.MapHttpRoute(
                name: "Version1",
                routeTemplate: "api/v1/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional , controllers = "studentV1" }
            );

my question is, if i need this code for a lot of controllers for example

controllers = "emplyeeV1" , controllers ="carV1" , controllers ="CursV1"

do i have to copy bast this code for each controller i have in the api ?!!

is there any way like this for exmaple.

   config.Routes.MapHttpRoute(
                name: "Version1",
                routeTemplate: "api/v1/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional , controllers = "studentV1" , controllers = "emplyeeV1" , controllers ="carV1" , controllers ="CursV1" }
            );

i know its wrong , but how can i do the right solution for this problem ?

1 Answers1

1

Have you evaluated ASP.NET API Versioning? It can support the type of routing you want to do out-of-the-box using a single route template. You can review all the details about versioning by URL segment on the wiki. There are also several Web API sample projects that demonstrate various setups and styles. I hope that helps.

Chris Martinez
  • 3,185
  • 12
  • 28