20

Closed

AjaxFileUpload assumes no query strings already exist in page URL on postback

description

When AjaxFileUpload post back it takes your page URL and appends onto the end of it it's own query strings (contextkey and guid). This works fine if your page URL doesn't already contain any query strings but if it does then you end up with a URL that contains two question marks which then corrupts your own final query string value and this in turn stops the upload from working.

file attachments

Closed Mar 28, 2013 at 6:36 AM by Superexpert
this issue is fixed with September 2012 release.

comments

marthinus wrote May 10, 2012 at 12:49 PM

I have run into this same problem, is there maybe a workaround for this?

stanleynik wrote May 18, 2012 at 5:29 PM

help me! i have this problem.

ravula_kish wrote May 22, 2012 at 12:09 PM

any workaround for query string issue

irecord wrote May 22, 2012 at 9:34 PM

The work around that I have found is to override the javascript 'AjaxFileUpload.js' file with a static one that has a tiny change to it.
The change is to check to see if 'this._postbackUrl' contains a '?' and if so add an '&' rather than the '?' to the querystring as it is appended. Unfortunately I can't log in to codeplex from work so this is from memory, if you search for '?context' it'll show up.

Hope that helps.

bwilliams80 wrote May 30, 2012 at 2:39 PM

I am running into the same problem. Any update on resolution?

dloc wrote May 31, 2012 at 3:25 PM

I've got the same issue, fix please.

bwilliams80 wrote Jun 2, 2012 at 11:34 PM

irecord is correct

AjaxFileUpload.pre.js - line 375
    uploader._vForm.action = uploader._postBackUrl + '?contextkey=' + this._contextKey + '&guid=' + this._guid;
changed to
    uploader._vForm.action = uploader._postBackUrl + '&contextkey=' + this._contextKey + '&guid=' + this._guid;

AjaxFileUpload.pre.js - line 176
this._webRequest.set_url(this._postBackUrl + '?contextkey=' + this._contextKey + '&guid=' + this._guid);

changed to
this._webRequest.set_url(this._postBackUrl + '&contextkey=' + this._contextKey + '&guid=' + this._guid);

I compiled, copied the AjaxControlToolkit.dll to the bin folder in my project. worked like a charm. someone with more time can add the logic irecord mentioned, but I only plan on using the upload with something in the querystring.
i attached my file if anybody is interested.

SilvioLuis wrote Jun 4, 2012 at 3:27 PM

instead of just replcing the lines i did a validation to cover both posibilities

Line 176
if (this._postBackUrl.indexOf('?') == -1)
        this._webRequest.set_url(this._postBackUrl + '?contextkey=' + this._contextKey + '&guid=' + this._guid);
    else
this._webRequest.set_url(this._postBackUrl + '&contextkey=' + this._contextKey + '&guid=' + this._guid);

Line 375
if (uploader._postBackUrl.indexOf('?') == -1)
        uploader._vForm.action = uploader._postBackUrl + '?contextkey=' + this._contextKey + '&guid=' + this._guid;
    else
        uploader._vForm.action = uploader._postBackUrl + '&contextkey=' + this._contextKey + '&guid=' + this._guid;

dloc wrote Jun 25, 2012 at 4:57 PM

I have added a pull request to fix this issue, please support this over here:
http://ajaxcontroltoolkit.codeplex.com/SourceControl/network/forks/dloc/FixedAjaxFileUpload/contribution/3022

Hansioli wrote Jun 26, 2012 at 10:09 AM

thanks for posting this. well done.

Hersilio wrote Jul 16, 2012 at 9:35 PM

it's working, tnks :)

Mar72vin wrote Jul 26, 2012 at 7:30 AM

any news on when this will be fixed?

Mar72vin wrote Jul 26, 2012 at 7:35 AM

sorry, just read that bwilliams80 attached a fixed dll. There are two attached files though. Does anyone know which one should be used?

jordan_12_ wrote Aug 13, 2012 at 8:44 AM

Could someone please post a download link for VS2008 .dll file. Thanks!

jordan_12_ wrote Aug 13, 2012 at 9:15 AM

I've figured out a workaround for me for now. I'm setting the variables in the query string to session variables then reloading the page without a query string. Works for me but would still appreciate a real solution.

jroland wrote Aug 13, 2012 at 2:33 PM

Hello,
This issue looks like a blocker to me because not supporting url with querystring avoid us any of us to use the control :-D

btw, there is a least 3 similar issues reported, #24917, #27163 , #27155

Mar72vin wrote Aug 14, 2012 at 8:13 AM

I made the necessary changes (thanks to SilvioLuis and bwilliams80) and compiled in VS2008 for my own project (see attached AjaxControlToolkit_VS2008.zip). I have tested it and it works well.

I also tried using session variables but it wasn't very elegant and cause other issues.

kuria wrote Aug 18, 2012 at 11:45 AM

Hi. I used "AJAX Control Toolkit is June 2012". I found this bug, so I tryed the 3 DLL on this page. I downloaded it and replace files in my BIN folder, but the problem still in my app.
This DLL are ok with June 2012 toolkit? What I forgot to use it?
thanks

thomasorton wrote Sep 13, 2012 at 10:12 PM

Adding my vote for it to be fixed.

thomasorton wrote Sep 13, 2012 at 10:23 PM

By the way for the record I slightly prefer:

this._webRequest.set_url(this._postBackUrl + (this._postBackUrl.indexOf("?") == -1 ? "?" : "&") + 'contextkey=' + this._contextKey + '&guid=' + this._guid);

and

uploader._vForm.action = uploader._postBackUrl + (this._postBackUrl.indexOf("?") == -1 ? "?" : "&") + 'contextkey=' + this._contextKey + '&guid=' + this._guid;

joeaudette wrote Mar 25, 2013 at 8:35 PM

I think this one is fixed in the latest release. I had no trouble using query string parameters of my own on the page with the uploader.

seascan wrote Sep 14, 2013 at 4:58 PM

Has anyone else noticed a recurrence of this issue with the latest builds (2013)?

I have the AjaxFileUpload inside of a usercontrol and the querystring is not recognized. The AsyncFileUpload works fine but does not allow for multiple files.

nESbo wrote Mar 1 at 3:36 PM

I had this problem when page contains query string on load. This is the solution I got (for 2013 release of the control). Three functions should be changed:
  1. Open AjaxFileUpload.Control.pre.js,
  2. find "doneAndUploadNextFile" function and make a change:
    original:
    xhr.open("POST", "?contextKey="+ this._contextKey +"&done=1&guid=" + fileItem._id, true);
changed:
var queryString = window.location.search.length <= 0 ? '?' : window.location.search.valueOf() + '&';
queryString += 'contextKey=' + this._contextKey + '&done=1&guid=' + fileItem._id;
xhr.open("POST", queryString, true);
  1. find "onUploadOrCancelButtonClickedHandler" function and make a change:
    original:
    xhr.open("POST", '?contextKey=' + this._contextKey
    • "&start=1&queue=" + this._filesInQueue.length);
changed:
var queryString = window.location.search.length <= 0 ? '?' : window.location.search.valueOf() + '&';
queryString += 'contextKey=' + this._contextKey
+ '&start=1&queue=' + this._filesInQueue.length;
xhr.open("POST", queryString);
  1. find "done" function and make a change:
    original:
    xhr.open("POST", '?contextKey=' + this._contextKey
    • "&complete=1&queue=" + this._filesInQueue.length
    • "&uploaded=" + (this._currentQueueIndex - (currentFile._isUploaded ? 0 : 1))
    • "&reason=" + (this._canceled ? "cancel" : "done"));
changed:
var queryString = window.location.search.length <= 0 ? '?' : window.location.search.valueOf() + '&';
queryString += 'contextKey=' + this._contextKey
+ '&complete=1&queue=' + this._filesInQueue.length
+ '&uploaded=' + (this._currentQueueIndex - (currentFile._isUploaded ? 0 : 1))
+ '&reason=' + (this._canceled ? 'cancel' : 'done');
xhr.open("POST", queryString);
  1. Build AjaxControlToolkit solution and upload new .dll file.

amatecki wrote May 8 at 9:32 PM

@nESbo:

i had the same problem, but it is other, simple solution for this.
It is not neccessary to modify source code of control, just use AjaxFileUpload object's property IsInFileUpluadPostBack in Page_Load event of your page.

So, if you check QueryString for any parameter existence in page Load event on initial load (not postback) and then do response redirect, then you must also check IsInFileUpluadPostBack property to make sure that load event is not caused by postback from AjaxFileUpload.

instead of:
protected void Page_Load(object sender, EventArgs e)
        {
            if ( ! IsPostBack )
            {
                if (Request.QueryString["key"] == null)
                    Response.Redirect("any.aspx");
            }
        }
write this:
protected void Page_Load(object sender, EventArgs e)
        {
            if ( ! IsPostBack && ! AjaxFileUpload.IsInFileUploadPostBack )
            {
                if (Request.QueryString["key"] == null)
                    Response.Redirect("any.aspx");
            }
        }

whamalek wrote May 9 at 10:15 PM

Thanks "amatecki",
This solution worked for me.