title: What's the best way to detect a JSON request on ASP.NET
body: <p>Most ajax frameworks seem to standardize with "X-Request-With" on either a header or the query string.</p>
  
  <p>And in ASP.NET MVC you can use the extension method</p>
  
  <pre><code>Request.IsAjaxRequest()
  </code></pre>
  
  <p>Because an ajax client can request several different content types, not just "application/json"  ex: "application/xml". </p>
  
  <p>I'm using the following code snippet/extension method, but I would love to see what others are doing or if there is something I missed, or a better way.</p>
  
  <pre><code>public static bool IsJsonRequest(this HttpRequestBase request)
  {
      return request.Headers["Accept"].Split(',') 
         .Any(t =&gt; t.Equals("application/json", StringComparison.OrdinalIgnoreCase));
  }
  </code></pre>
  
  <p>Thanks in advance.</p>