title: Attribute routing with optional parameters in ASP.NET Web API
body: <p>I'm trying to use Web API 2 attribute routing to set up a custom API. I've got my route working such that my function gets called, but for some reason I need to pass in my first parameter for everything to work properly. The following are the URLs I want to support:</p>
  
  <pre><code>http://mysite/api/servicename/parameter1
  http://mysite/api/servicename/parameter1?parameter2=value2
  http://mysite/api/servicename/parameter1?parameter2=value2&amp;parameter3=value3
  http://mysite/api/servicename/parameter1?parameter2=value2&amp;parameter3=value3&amp;p4=v4
  </code></pre>
  
  <p>The last 3 URLs work but the first one says "No action was found on the controller 'controller name' that matches the request."</p>
  
  <p>My controller looks like this:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class MyServiceController : ApiController
  {
      [Route("api/servicename/{parameter1}")]
      [HttpGet]
      public async Task&lt;ReturnType&gt; Get(string parameter1, DateTime? parameter2, string parameter3 = "", string p4 = "")
      {
          // process
      }
  }
  </code></pre>