title: Check for Ajax Request
body: <p>I've researched how to check if a request is sent via AJAX in C#, but it doesn't seem to be working for me. My code is below. I use a method to AJAX a page in clientside (in my case, the activeXobject is being used). The ajaxed page is checking the request of ajax properties serverside, but neither of the X-Requested-With properties return anything (I get blanks on print out). Ideas?</p>
  
  <p>Ajax Method (Javascript)</p>
  
  <pre><code>/*
  * Ajax page loads with url
  * @param url : URL to call for ajax page load
  * @param element : Element ID to be updated
  */
  function ajax(url, element) {
      UtilLogger.log(HtmlLogger.INFO, "-AJAX Call for " + url + " in " + element + "-");
      var ajx;
      if (window.HXMLHttpRequest) {
          UtilLogger.log(HtmlLogger.FINE, "Using XMLHttpRequest");
          ajx = new XMLHttpRequest();
      }
      else {
          UtilLogger.log(HtmlLogger.FINE, "Using ActiveXObject");
          ajx = new ActiveXObject("Microsoft.XMLHTTP");
      }
      ajx.open("GET", url, true);
      ajx.send();
      ajx.onreadystatechange = function () {
          if (ajx.readyState == 4 &amp;&amp; ajx.status == 200) {
              document.getElementById(element).innerHTML = ajx.responseText;
          }
          else if (ajx.readyState == 4 &amp;&amp; ajx.status == 400) {
              alert("Page Error. Please refresh and try again.");
          }
          else if (ajx.readyState == 4 &amp;&amp; ajx.status == 500) {
              alert("Server Error. Please refresh and try again.");
          }
      }
      UtilLogger.log(HtmlLogger.INFO, "-END AJAX Call for " + url + " in " + element + "-");
  }
  </code></pre>
  
  <p>Ajax Login Check (C#)</p>
  
  <pre><code>/* Checks for ajax request validity
   * @param HttpResponse resp : response to redirect if not ajax request
   * @param HttpRequest req : request to check for ajax
   */
  public static void checkAjax(HttpResponse resp, HttpRequest req)
  {
      if(req == null || 
          (req["X-Requested-With"] != "XMLHttpRequest" &amp;&amp; 
          (req.Headers != null &amp;&amp; req.Headers["X-Requested-With"] != "XMLHttpRequest"))){
             // resp.Redirect("./ajaxerror.aspx");
              resp.Write(req["X-Requested-With"] + ":" + req.Headers["X-Requested-With"]);
      }
  }
  </code></pre>