13
Uri uri = new Uri(redirectionUrl); NameValueCollection col = HttpUtility.ParseQueryString(uri.Query) 

uri.Query is already decoded - so is there any way I can prevent ParseQueryString decoding it again?

Apart from that - is there another method to retrieve a name value collection from a Uri without modifying any components?

2 Answers 2

8

Encoding the uri.Query before passing it to ParseQueryString is the first thing that comes to my head.

UPDATE

Just checked the ParseQueryString method with Reflector: it assumes that the query string is encoded and you can't do anything with it... Bummer. So I think you need to parse it manually (there are plenty of ready-to-use algorithms on the Web).

Alternatively you could encode your query string properly (taking into account variable names and all special characters) before passing it to ParseQueryString method.

-- Pavel

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

2 Comments

I can't as uri.Query includes the variable name and ? =
I've updated my answer. Hope this will help you to do a right decision.
-4

I have faced the same problem. The solution is adding the second parameter - the encoding. It seams that everything works if you set UTF8 encoding.

NameValueCollection col = HttpUtility.ParseQueryString(uri.Query, Encoding.UTF8) 

3 Comments

UTF8 encoding is used by default, so adding it explicitly does not have any effect: msdn.microsoft.com/en-us/library/ms150046(v=vs.110).aspx
This option does not have any effect
This unfortunately does not have any effect. You should encode your query string properly prior to passing it to ParseQueryString.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.