According to the AttributeRouting website, it does not support some features under WebApi, including custom handlers. Think you might be out of luck.
Beware! Due to integration issues with the Web API WebHost framework,
the following features will not work:
performance enhancements when matching routes, custom route handlers,
querystring parameter constraints, subdomain routing, localization
applied to inbound/outbound urls, and lowercasing, appending prefixes,
etc to generated routes. These features all have to wait for vNext of
the Web API.
If you don't need all the extensive routing that AttibuteRouting provides, you could use your own route attribute and then register routes based on that during startup. e.g.:
public class RouteAttribute : Attribute
{
public string Value { get; private set; }
public RouteAttribute (string value)
{
Value = value;
}
}
then register routes based on decorating class or action in your controller:
foreach (var controllerType in controllers)
{
var attributes = System.ComponentModel.TypeDescriptor.GetAttributes(controllerType);
var uriattribute = (RouteAttribute)attributes[typeof(RouteAttribute)];
var controllerName = controllerType.Name.Replace("Controller", "");
string uri = uriattribute.Value;
config.Routes.MapHttpRoute(
name: controllerName,
routeTemplate: uri,
handler: new YourCustomHandler()
}
}
Obviously you don't want to rewrite AttributeRouting, but if your needs are simple it could be an option.