Search code examples
c#asp.netasp.net-web-apiasp.net-web-api2asp.net-web-api-routing

ASP.NET Web API extending DefaultDirectRouteProvider


I'm trying to create a CustomerDefaultDirectRouteProvider that extends DefaultDirectRouteProvider in Web API 2.2, as in this example. However, when I implement the method GetActionRouteFactories(HttpActionDescriptor actionDescriptor), I get the error "no suitable method found to override".

I am able to override GetActionRouteFactories(ActionDescriptor actionDescriptor), but the ActionDescriptor class does not have the method GetCustomAttributes<IDirectRouteFactory>.

I am importing the following namespaces:

using System.Collections.Generic;
using System.Web.Mvc;
using System.Web.Mvc.Routing;
using System.Web.Routing;
using System.Web.Http.Controllers;

Am I missing some, perhaps?


Solution

  • You are mixing MVC and WebAPI. Both have the DefaultDirectRouteProvider class. I suggest you remove the .Mvc-namespaces and use the one from System.Web.Http.Routing.