ASP.NET Web API - method that is called for all requests prior to the routed method?
<p>I'm writing in C# for ASP.NET Web API 2. What I want is a catch-all method that will execute for every single request that comes to my Web API.</p>

<p>If the method returns null, then the original routing should continue, seeking out the correct method. However, if the method returns, say, an HTTPResponseMessage, the server should return that response and not proceed on to normal routing.</p>

<p>The use case would be the ability to handle various scenarios that may impact the entire API. For example: ban a single IP address, block (or whitelist) certain user agents, deal with API call counting (e.g. someone can only make X requests to <em>any</em> API method in Y minutes).</p>

<p>The only way I can imagine to do this right now is to literally include a method call in each and every new method I write for my API. For example, </p>

<pre><code>[HttpGet]
public HttpResponseMessage myNewMethod()
{
    // I want to avoid having to do this in every single method.
    var check = methodThatEitherReturnsResponseOrNull(Request);
    if (check != null) return (HttpResponseMessage)check;

    // The method returned null so we go ahead with normal processing.
    ...
}
</code></pre>

<p>Is there some way to accomplish this in routing? </p>