title: WCF Data Services, filtering $metadata requests
body: <p>I'm looking for a clean way to differentiate <code>$metadata</code> requests from entity requests with WCF Data Services (<em>5.5.0</em>).</p>
  
  <p>Rather than apply authentication at the at the HTTP module level (<em>as a registered <code>IHttpModule</code></em>) it seems I would have to apply it later in the request life-cycle.</p>
  
  <p>Unfortunately, the only "later"-time that it seems I can apply it (<em>and not have it interfere with <code>$metadata</code> requests</em>) is in <code>QueryInterceptor</code> methods. The problem here is, there is a number of them, and it just seems silly that I'd have to duplicate even a method call across all of them to authenticate requests.</p>
  
  <p>My question boils down to: at what point in the WCF Data Services request life-cycle should I perform authentication and not have it interfere with <code>$metadata</code> requests; <em>or</em>, how should I test if a request is for <code>$metadata</code> so I can promote the authentication logic back to a higher method.</p>
  
  <p>It seems to me like there would (<em>read: should</em>) be an <code>IsMetadataRequest</code> property floating around, thus allowing:</p>
  
  <pre><code>protected override void OnStartProcessingRequest(ProcessRequestArgs args) {
      base.OnStartProcessingRequest(args);
      if (IsMetadataRequest) {
          return;
      }
      // proceed with auth
  }
  </code></pre>
  
  <p>I can hack something out into a service base class that simply reads the URI, but it seems like there should be something more defined.</p>