I was able to find a decent solution using MVC areas.
First, I wanted my API to match this url. Definition:
http://[website]/[major_version]_[minor_version]/{controller}/{action}/...
I also wanted to split different versions in separate Project files and use the same controller names in each version:
"../v1_0/Orders/ViewOrders/.." => "../v2_3/Orders/ViewOrders/.."
I searched and found a workable solution using MVC scopes.
I created a new project in my solution called "Api.Controllers.v1_0" and, as a test, put the SystemController.cs file:
using System.Web.Mvc; namespace Api.Controllers.v1_0 { public class SystemController : Controller { public ActionResult Index() { return new ContentResult() {Content = "VERSION 1.0"}; } } }
Then I added the file v1_0AreaRegistration.cs :
using System.Web.Mvc; namespace Api.Controllers.v1_0 { public class v1_0AreaRegistration : AreaRegistration { public override string AreaName { get{ return "v1_0";} } public override void RegisterArea(AreaRegistrationContext context) { context.MapRoute( "v1_0", "v1_0/{controller}/{action}/{id}", new { controller = "System", action = "Index", id = UrlParameter.Optional } ); } } }
I went through the same steps above for the project "..v1_1" with the corresponding files there, added the projects as links to my MVC project "Api.Web" and was turned off and started.
source share