title: How can I restrict a delegating handler to a specific route in Web API?
body: <p>I have a custom delegating handler that manages the authentication of a request. In one of my controllers, authentication should not be enabled for a specific action. How can I disable the delegating handler for the method and route <code>POST api/MyController</code>?</p>
  
  <p>One option is to hard code the route inside the handler, however, I would rather keep this logic out of the handler. In addition, I see myself adding this behavior to a few more actions, which can make this method hard to maintain.</p>
  
  <pre><code>protected override System.Threading.Tasks.Task&lt;HttpResponseMessage&gt; SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
  {
      if (request.Method == HttpMethod.Post
          &amp;&amp; request.RequestUri.PathAndQuery.StartsWith("/api/MyController"))
          return base.SendAsync(request, cancellationToken);
  
      // Do authentication
  }
  </code></pre>
  
  <p>Is there a better way that's easier to maintain?</p>