title: Web API 2 routing attributes not working
body: <p>I'm using the final release versions of .NET 4.5 and Web API 2 (in Visual Studio 2013). I've been using <a href="http://aspnetwebstack.codeplex.com/wikipage?title=Attribute%20routing%20in%20MVC%20and%20Web%20API&amp;referringTitle=Specs">this documentation</a> as a reference, to no avail.</p>
  
  <p>I have a few base routes like</p>
  
  <pre><code>api/providers
  api/locations
  api/specialties
  </code></pre>
  
  <p>And some methods on each like</p>
  
  <pre><code>Get()
  Get(int id)
  Get(string keyword)
  Autocomplete(string keyword)
  Search(string zipcode, string name, int radius, [...])
  </code></pre>
  
  <p>Ideally, I'd like the URLs to end up like</p>
  
  <ul>
  <li><strong>/api/locations/12345</strong> (get location 12345)</li>
  <li><strong>/api/locations/clinical</strong> (get locations with "clinical" in the name)</li>
  <li><strong>/api/locations/autocomplete?keyword=clinical</strong>
  (get a condensed Id + Name object for locations with "clinical" in the name)</li>
  <li><strong>/api/locations/search?zipcode=12345&amp;radius=20&amp;name=clinical</strong>
  (get locations within 20 miles of zip 12345 with "clinical" in the name)</li>
  </ul>
  
  <p>In the chunk of code below, the <code>Get</code> methods and <code>Search</code> work as desired, but <code>Autocomplete</code> does not. It should be noted I have similarly named methods in multiple controllers. What am I doing wrong? (Also, what exactly is the <code>Name =</code> property for?)</p>
  
  <pre><code>/// &lt;summary&gt;
  /// This is the API used to interact with location information.
  /// &lt;/summary&gt;
  [RoutePrefix("api/locations")]
  public class LocationController : ApiController
  {
      private ProviderEntities db = new ProviderEntities();
  
      private static readonly Expression&lt;Func&lt;Location, LocationAutocompleteDto&gt;&gt; AsLocationAutocompleteDto =
          x =&gt; new LocationAutocompleteDto
          {
              Id = x.Id,
              Name = x.Name
          };
  
      /// &lt;summary&gt;
      /// Get ALL locations.
      /// &lt;/summary&gt;
      [Route("")]
      public IQueryable&lt;Location&gt; Get()
      {
          return db.Locations.AsQueryable();
      }
  
      /// &lt;summary&gt;
      /// Get a specific location.
      /// &lt;/summary&gt;
      /// &lt;param name="id"&gt;The ID of a particular location.&lt;/param&gt;
      [Route("{id:int}")]
      public IQueryable&lt;Location&gt; Get(int id)
      {
          return db.Locations.Where(l =&gt; l.Id == id);
      }
  
      /// &lt;summary&gt;
      /// Get all locations that contain a keyword.
      /// &lt;/summary&gt;
      /// &lt;param name="keyword"&gt;The keyword to search for in a location name.&lt;/param&gt;
      [Route("{keyword:alpha}")]
      public IQueryable&lt;Location&gt; Get(string keyword)
      {
          return db.Locations.Where(l =&gt; l.Name.Contains(keyword)).OrderBy(l =&gt; l.Name);
      }
  
      [Route("search", Name = "locationsearch")]
      public string Search(string zipcode = null, string latitude = null, string longitude = null)
      {
          if (zipcode != null) return "zipcode";
          if (latitude != null &amp;&amp; longitude != null) return "lat/long";
          else
              return "invalid search";
      }
  
      /// &lt;summary&gt;
      /// Autocomplete service for locations, returns simple Id/Name pairs.
      /// &lt;/summary&gt;
      /// &lt;param name="keyword"&gt;The keyword to search on.&lt;/param&gt;
      [Route("autocomplete/{keyword:alpha}", Name = "locationautocomplete")]
      public IQueryable&lt;LocationAutocompleteDto&gt; Autocomplete(string keyword)
      {
          // validate the inputs
          if (string.IsNullOrEmpty(keyword))
              return null;
  
          IQueryable&lt;Location&gt; results = from l in db.Locations
                                         where l.Name.Contains(keyword)
                                         select l;
  
          return results.Select(AsLocationAutocompleteDto);
      }
  </code></pre>
  
  <p>There does not seem to be a lot of community support around the latest versions of this stuff yet.</p>
  
  <h1>EDIT (with answer)</h1>
  
  <p>Simply replaced</p>
  
  <pre><code>[Route("autocomplete/{keyword:alpha}", Name = "locationautocomplete")]
  </code></pre>
  
  <p>with</p>
  
  <pre><code>[Route("autocomplete"), Route("autocomplete/{keyword:alpha}", HttpGet()]
  </code></pre>
  
  <p>and it works perfectly.</p>