BuildQueryString with FriendlyUrls (CMS 5)

Member since: 2006
I'm having a bit of a problem regarding the UriSupport.BuildQueryString method.  I have this link to which I want to add three parameters. I do the following:

NameValueCollection myCol = new NameValueCollection();

            myCol.Add("Comment", "false");

            myCol.Add("EditMode", "true");

string redirect = CurrentPage.LinkURL + UriSupport.BuildQueryString(myCol);

When I click my link the page can't be displayed. I've altered the code above several times but with no luck. Does anybody have any solutions to my problem?

#29847 May 19, 2009 9:56
  • Mari Jørgensen
    Member since: 2003

    I've used the BuildQueryString method without any problems.

    What is the value of your redirect string?

    #29848 May 19, 2009 10:32
  • nihut
    Member since: 2006

    Ok, dp you have any sample code I can look at?

    My redirect string from the code above looks like this:


    As you can see it's wrong :-)

    #29849 May 19, 2009 10:44
  • Erik Nordin Wahlberg
    Member since: 2004

    I would use an UrlBuilder instead.

    UrlBuilder ub = new UrlBuilder(CurrentPage.LinkURL);
    ub.QueryCollection.Add("parameter1", "value1");
    ub.QueryCollection.Add("parameter2", "value2");
    Response.Redirect(ub.ToString(), true);

     The problem with your approach is that you append the correctly built "BuildQueryString", but you miss the "&"/"?" between the strings when you just concat them.

    #29852 May 19, 2009 11:05
  • nihut
    Member since: 2006
    Tack! Funkar perfekt!
    #29867 May 19, 2009 15:33