I just realized I totally did not answer the question, so I am adding to the top here, and leaving my old answer below:
The problem is when posting a file over an iFrame, the "X-Requested-With" header is not set and you cannot set specific request headers for a normal form POST in Javascript. You'll have to resort to other tricks, like sending a hidden field with your POST that contains a value, and then change or override the "IsAjaxRequest" extension method to also check for this condition.
How to override an existing extension method?
Probably the best option would probably be to include your own extension method with a different name, based off the default MVC extension method code with the changes to detect your iFrame upload POST, and then use your extension method anywhere where you expect to need it.
jQuery actually sets the 'X-Requested-With' header to 'XMLHttpRequest' by default. It is quite useful as long as you are careful to do all your AJAX calls over jQuery.
Depending on your needs, it's easy to setup the detection in an action filter to use it where needed, or even build it into a controller class like so:
[jQueryPartial]
public abstract class MyController : Controller
{
public bool IsAjaxRequest { get; set; }
}
The ActionFilterAttribute:
public class jQueryPartial : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
// Verify if a XMLHttpRequest is fired.
// This can be done by checking the X-Requested-With
// HTTP header.
MyController myController = filterContext.Controller as MyController;
if (myController != null)
{
if (filterContext.HttpContext.Request.Headers["X-Requested-With"] != null
&& filterContext.HttpContext.Request.Headers["X-Requested-With"] == "XMLHttpRequest")
{
myController.IsAjaxRequest = true;
}
else
{
myController.IsAjaxRequest = false;
}
}
}
}
And using the implementation:
public class SomeController : MyController
{
public ActionResult Index()
{
if (IsAjaxRequest)
DoThis();
else
DoThat();
return View();
}
}