IT:AD:ASP.NET:WebAPI:HowTo:Configure WebAPI Routing defining Namespaces
Summary
When there are two controllers with the same name, but in different namespaces, MVC can't decide which one to use, unless the route has a namespace contraint of some kind.
There is an overload in MVC that allows this to be defined, but not in WebAPI.
Process
The work around to this omission is as follows:
r = context.Routes.MapHttpRoute(
"API.V2_default",
"api/v2/{controller}/{action}/{id}",
new { version = AreaName, action = "Index", id = UrlParameter.Optional },
null
);
if (r.DataTokens == null)
{
r.DataTokens = new RouteValueDictionary();
}
r.DataTokens["Namespaces"] = new string[] { "XAct.Spikes.WebAPI.I03.Areas.API.V2.Controllers" };