title: Configuring Web API with URL Rewrite installed on IIS
body: <p>We have a Web Forms application that uses ASP.Net <em>URL Rewrite 2.0</em>.  The following rewrite rule is configured to enable access to certain pages without specifying the <code>.ashx</code> extension:</p>
  
  <pre><code>&lt;rule name="RewriteASHX"&gt;
      &lt;match url="(customers|orders|products.*)"/&gt;
      &lt;conditions logicalGrouping="MatchAll"&gt;
        &lt;add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/&gt;
        &lt;add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/&gt;
      &lt;/conditions&gt;
      &lt;action type="Rewrite" url="{R:1}.ashx"/&gt;
  &lt;/rule&gt;
  </code></pre>
  
  <p>Using Web API, we want to gradually replace our Web Forms-based API pages with Web API controllers.  With URL Rewrite installed, only controllers matching the above rule will route correctly to the Web API controller.  (Adding exclusions to the URL Rewrite rules seems to not let the request make it to the controller at all, giving a 404 result.)</p>
  
  <p>The Web API controllers are set up in the following manner:</p>
  
  <pre><code>public class CustomersController : ApiController
  {
      [Route("api/v2/customers")]
      [ResponseType(typeof(CustomerCollection))]
      public IHttpActionResult Get()
      {
          ...
      }
  
      [Route("api/v2/customers/{identifier}")]
      [ResponseType(typeof(Customer))]
      public IHttpActionResult Get(string identifier)
      {
          ...
      }
  }
  </code></pre>
  
  <p>As described above, we have only been able to get Web API requests to route if they match a URL Rewrite condition.</p>
  
  <blockquote>
    <p>The parameterless <code>api/v2/customers</code> in <code>CustomerController</code> works because it matches <code>&lt;match url="(customers|orders|products.*)"/&gt;</code>, but <code>api/v2/customers/C123</code> fails because it does not match the rewrite condition.</p>
  </blockquote>
  
  <p><strong>What is the best way to configure URL Rewrite to allow Web API requests to route properly?</strong></p>