I'm having trouble getting WEBAPI 2 attribute routing to work. The routing scheme I'm looking for is /api/{product}/{controller}/{id-optional}
, so like /api/Vision/IdCard
. The controllers are in an area and are set up like this:
namespace DataServices.Controllers.Vision
{
[RoutePrefix("api/vision")]
public class IdCardController : BaseApiController
{
[System.Web.Mvc.RequireHttps]
[Route("idcard")]
public IdCardViewModel Get(HttpRequestMessage request)
{...}
Whenever I do a get to this, I get a 404. I included the namespace as the area is in it's own namespace. Are areas supported in WEBAPI attribute routing?
EDIT: WebApiConfig looks like this:
config.SuppressDefaultHostAuthentication();
config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
Try play with initialization order in
Application_Start
Thus:GlobalConfiguration.Configure(WebApiConfig.Register);
AreaRegistration.RegisterAllAreas();
Order is very important (if i reverse areaRegistration with WebApiConfig => WebAPI 2 attributeRouting won't work