title: Tricking ASP.NET into Thinking Request is Ajax Request for jQuery File Upload
body: <p>I am using a rescue derived from MvcContrib:</p>
  
  <pre><code>public class RescueAttribute : MvcContrib.Filters.RescueAttribute
  {
      public RescueAttribute(string view) : base(view)
      {
          IgnoreAjax = false;
      }
  
      public RescueAttribute(string view, params Type[] exceptionTypes) : base(view, exceptionTypes)
      {
          IgnoreAjax = false;
      }
  
      protected override ActionResult CreateActionResult(Exception exception, ExceptionContext context)
      {
          var controller = (string) context.RouteData.Values["controller"];
          var action = (string) context.RouteData.Values["action"];
          var model = new HandleErrorInfo(exception, controller, action);
  
          if (context.Controller.ControllerContext.HttpContext.Request.IsAjaxRequest())
          {
              return new JsonResult(model);
          }
          return base.CreateActionResult(exception, context);
      }
  }
  </code></pre>
  
  <p>Now when using the file upload in jQuery.form, Request.IsAjaxRequest() returns false. Apparently this is because you can't actually upload a file using json; this plugin generates a hidden iframe to do the upload. </p>
  
  <p>To compensate I am appending a hidden input to any form that is submitted with jquery.form and has file inputs:</p>
  
  <pre><code>$(this).append('&lt;input type="hidden" name="X-Requested-With" value="XMLHttpRequest" /&gt;');
  </code></pre>
  
  <p>It's good enough to fool IsAjaxRequest. Is there any reason why I <strong>shouldn't</strong> do this?</p>