2

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"

5
  • 4
    Can you give an explicit example of your URL before and after encoding and how you're encoding - you seem to explain that encoding is cutting off query string parameter names but it's hard to tell why with the information given. Commented Oct 5, 2012 at 11:37
  • How do you encode/decode query string? Commented Oct 5, 2012 at 11:38
  • Can you post an example with code what you do? Commented Oct 5, 2012 at 11:41
  • Based on your update there are plenty of issues here. First one to tackle is escaping certain characters, specifically the double quotes here since they're messing with your string and not concatenating as you expect. Commented Oct 5, 2012 at 12:34
  • lets make it more simple.please refer the change. Commented Oct 5, 2012 at 13:03

2 Answers 2

5

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

Sign up to request clarification or add additional context in comments.

2 Comments

you mean where I read the query string or instead of HttpUtility.HtmlEncode?
I have edited my answer, check out the link, it should be helpful.
3

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.