Url Encoding with Multiple Query String Parameters

14,646

Solution 1

Use HttpUtility.UrlEncode, I bet it will work like a charm. Read this article for more information.

Solution 2

The biggest issue is that you're encoding the whole query string. You need to encode the individual components, then concatenate them together.

Share:
14,646
V.B
Author by

V.B

Updated on June 05, 2022

Comments

  • V.B
    V.B almost 2 years

    In my c# code I am encoding my Url that has multiple query strings. When at the receiver end I try to read back the query strings I get the null values (query string parameter is not found) reason being encoding changes &querystringparameter to &querystringparam. How to get around this.

    Response.Redirect(HttpUtility.HtmlEncode("Add.aspx?ID=" + 1 + "&cid="+ 8 + "&jid=" +9));
    

    On the add.aspx page i get the url as "add.aspx?id=1&sid=3&jid=9"

  • V.B
    V.B over 11 years
    you mean where I read the query string or instead of HttpUtility.HtmlEncode?
  • Lajos Arpad
    Lajos Arpad over 11 years
    I have edited my answer, check out the link, it should be helpful.