blueimp/jQuery-File-Upload — Issue #1054: Issue with Net MVC and IE
Author: ranauk
Created: 2012-02-27 05:16:48+00:00
State: open

Hi BlueImp,

first of all, thanks for such a lovely plugin - really neat job.

Now to the issue; obviously I want to have an unobtrusive form : on my post method I am using a MVC command Request.IsAjaxRequest(), and depending on if it's a ajax request or not, I either redirect them to another page, or return json result.

This Request.IsAjaxRequest() is true when header has an element "X-Requested-With" with value of "XMLHttpRequest" (case-sensitive for mvc)

Ofcourse on chrome/firefox using xhr method, it sends that header and everything is okay; However, with IE posting over iFrame, I am getting false for that method, and can't distinguish between ajax/non-ajax post.

I had similar issue when using "jQuery Form Plugin" - however, with that plugin, I could submit [data An object containing extra data that should be submitted along with the form.] - my code looks like...
data: { "X-Requested-With": "XMLHttpRequest" }

that worked perfectly. This is what I get using IE developer tools...

Content-Disposition: form-data; name="__RequestVerificationToken"

FwSx1nj/JKVGQC22LPx4GC/Ncc2ylTCUaquATJUuSKtvs4J53xEMLNFqMg4G8miEijQdDIZML35RCGwgMbL4ZxYaDlABMCPFYHwNcpg/9KBJz9h5M8xpraK26UvLOO+prCEyQxzTNkM65jkaDHcMfep1z9ghtnqU6LExOrsEnOY=
-----------------------------7dc2aa1e18a0886
Content-Disposition: form-data; name="fileData"; filename="C:\Users\Administrator\Desktop\2012-02-22_235216.png"
Content-Type: image/png

---------------------------7dc2aa1e18a0886
Content-Disposition: form-data; name="X-Requested-With"

XMLHttpRequest
-----------------------------7dc2aa1e18a0886--

Now with your plugin, I tried similar method of formData; however, I am also using MVC method of AntiForgeryToken and ValidateAntiForgeryToken - including formData causes validation of Forgery Token to fail.

I have tried including X-Requested-With as hidden item and then updating the value using javascript on body load; in that case validation of Forgery doesn't fail, but IE developer tools doesn't show X-Requested-With being passed anywhere and doesn't show up as Ajax.

Ideally I thought I could do following:

beforeSend: function (e, data) {
e.setRequestHeader("X-Requested-With", "XMLHttpRequest");
}

but that didn't do anything either; I can see with breakpoint that it's being hit, but nothing in header.

Any suggestions? Thanks again for this awesome work..

Rana