title: How to override a web api route?
body: <p>I am trying to standardize an extension model for our REST API development team. We need to provide default implementation of routes, while allowing for custom implementations of routes that replace the default as well.</p>
  
  <p>As a simple example if we have a GET route <code>api/users</code> like this:</p>
  
  <pre><code>public class DefaultUsersController : ApiController
  {
      [HttpGet]
      [Route("api/users", Order = 0)]
      public IEnumerable&lt;string&gt; DefaultGetUsers()
      {
          return new List&lt;string&gt;
          {
              "DefaultUser1",
              "DefaultUser2"
          };
      }
  }
  </code></pre>
  
  <p>We expect the default work like this:</p>
  
  <p><img src="https://i.stack.imgur.com/n6vpm.png" alt="enter image description here"></p>
  
  <p>Now a developer wants to change the behavior of that route, he should be able to simply define the same route with <strong>some mechanism to imply their implementation should be the one used, instead of the default</strong>. My initial thinking was to use the <a href="http://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2#order" rel="nofollow noreferrer">Order property on the Route attribute</a> since that's what it appears to be there for, as a way to provide a priority (in ascending order) when an ambiguous route is discovered. However it's not working that way, consider this custom implementation that we want to override the default <code>api/users</code> route:</p>
  
  <pre><code>public class CustomUsersController : ApiController
  {
      [HttpGet]
      [Route("api/users", Order = -1)]
      public IEnumerable&lt;string&gt; CustomGetUsers()
      {
          return new List&lt;string&gt;
          {
              "CustomUser1",
              "CustomUser2"
          };
      }
  }
  </code></pre>
  
  <p>Notice the Order property is set to -1 to give it a lower priority value than the default, which is set to 0. I would have thought this would be used by the <a href="http://msdn.microsoft.com/en-us/library/system.web.http.dispatcher.defaulthttpcontrollerselector(v=vs.118).aspx" rel="nofollow noreferrer">DefaultHttpControllerSelector</a>, but it isn't. From the <code>DefaultHttpControllerSelector</code>:</p>
  
  <p><img src="https://i.stack.imgur.com/022FX.png" alt="enter image description here"></p>
  
  <p>And we end up with this exception being returned in the response:</p>
  
  <p><img src="https://i.stack.imgur.com/FLztM.png" alt="enter image description here"></p>
  
  <p>Is it possible Microsoft just missed the logic/requirement to use <code>Order</code> as a route disambiguator and this is a bug? Or is there another simple way to override a route, hopefully with an attribute?</p>