Programatically setting RoutePrefix with Attribute Routing

Topics: ASP.NET Web API
Feb 14, 2014 at 3:07 PM
I am currently working on an expandable WebApi where individual dynamically loaded modules can register their own routes. My original version was built using ASP.NET WebApi v1 using a technique based on however I would like to use the Attribute based routing that is available with ASP.NET WebApi v2

So say I have a module with the following Controller
public class FooController : ApiController {

    public object GetFoo(int id) {
        return id;
If I just call config.MapHttpAttributeRoutes() then that controller would be bound to http://localhost/foo/2. What I would like to do is programmatically change the route prefix for the controllers. So it should hopefully be bound to something like http://localhost/modules/FooModule/foo/2

Is there a way to get this done with the provided tools, or would I have to keep using my original method?