2

I have a javascript code like this :

function OnRequestComplete(result) {
        // Download the file
        //Tell browser to open file directly
        alert(result);
        var requestImage = "Handler.ashx?path=" + result;
        document.location = requestImage;
}

and Handler.ashx code is like this :

public void ProcessRequest(HttpContext context)
{
    Context = context;
    string filePath = context.Request.QueryString["path"];
    filePath = context.Server.MapPath(filePath);
}   

In filePath we don't have any + signs (spaces instead).
How can I solve this issue ?
Why does Request.QueryString["path"] converts all + signs to spaces ?

HoLyVieR
  • 10,745
  • 5
  • 42
  • 66
SilverLight
  • 18,804
  • 60
  • 181
  • 287

1 Answers1

4

When you correctly encode the query string a space becomes + and + becomes %2B. The process of decoding does the reverse, which is why your + gets turned into a space.

The problem is that you didn't encode the query string, and that means it gets decoded incorrectly.

var requestImage = "Handler.ashx?path=" + encodeURIComponent(result);
Community
  • 1
  • 1
Mark Byers
  • 767,688
  • 176
  • 1,542
  • 1,434