I have a project (named Product.Api
) that has some controllers used for our WebAPI site. The controllers are in a namespace Product.Api.Controllers
. Th
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new {id = RouteParameter.Optional}
).Constraints["Namespaces"] = new string[] { "Product.Api.Controllers" };
this will not work with MapHttpRoute.
If you want to use ApiController routes from the other bin, just remove the constraints, the runtime will automatically pick up your ApiControllers from the bin. MapHttpRoute will not interfere with your MVC controllers and vice versa, so the constraints are not needed anyway.
Alternatively use this to contraint your HttpRoute namespace
routes.DataTokens["Namespaces"] = new string[] {"MyNamespace"};
Or use this solution (but that's really only needed if you keep stuff outside of bin.)
Before the MapHttpRoute Factory call add System.Web.Mvc.ControllerBuilder.Current.DefaultNamespaces.Add("Namespace.Full.Controllers");