Ampersand

Hi,
I'm having trouble with an ampersand in my URI. I'm working in a winform with a webbrowser. This is my code:

String test1 = "http://serv/reportserver /CUBE/CUBE02&rs:Command=Render&Budget=[Budget].[N Budget].";

String Testen =
test1 + "%26[1]"; (%26 is the same as &)

webBrowser1.Url = new Uri(Testen);


When the browsers opens he converts the url to :
http://serv/reportserver /CUBE/CUBE02&rs:Command=Render&Budget=[Budget].[N Budget].&[1]

He must not do that ! I tried everything (HttpUtility.urlEncode, ASCII encoding,...) The browser seems to convert it allways. Is there a way to resolve this


Answer this question

Ampersand

  • Siggy

    Couldn't you just type string a = @"You can put /n in this string now and it will not show as an escape character" I know this works in a winForm application.

  • Anab

    The thing with @ doesn't work, %2526 also... He seems to convert it always to &...

  • Jish40289

    woeter,
    the %2526 works here... If I write:

    webBrowser1.Url = new Uri ("http://localhost/test/test.aspx dummy=%2526moredata");

    and then I have my ASP.NET app return the query string, I correctly see the "%26" in the string.

    Now, if I were to call HtmlDecode on the QueryString somewhere, that would indeed become a "&"...

    If you don't have access to the application (if you had, I guess you would have already changed your syntax), you might want to try further escaping the "%". Each time the string is decoded, a "%25" is converted to a "%".

    Try sending "%252526", then "%25252526", then "%2525252526" ....

    Hopefully, you will finally match the number of times the string is decoded. If the application is not consistent in the number of times it decodes the query, this won't work.

    HTH
    --mc


  • RKellogg

    Beat him at his own game.

    According to the RFC (2396, I think), the % is always escaped unless followed by exactly two hex digits.

    So, in your case, you should write: "%2526", where %25 is the percent itself, and 26 are your digits. Your web app will correctly see "%26" in the query string.

    HTH
    --mc


  • Philip Fortier - MSFT

    The Uri class escapes the string you give it, meaning it automatically converts your "%26" to "&". In .NET 2.0 there's no way that I know of to get around this.

  • bluebunny

    hi,

    %26 shows &
    %25 shows %25
    %2526 shows &.
    %252526 shows %2526

    It's wierd !!



  • Ampersand