I would like to parse a string such as "p1=6&p2=7&p3=8" into a NameValueCollection.
What is the most elegant way of doing this when you don't have access to the Page.Request object?
I would like to parse a string such as "p1=6&p2=7&p3=8" into a NameValueCollection. What is the most elegant way of doing this when you don't have access to the Page.Request object? |
||||
|
There's a built-in .NET utility for this: HttpUtility.ParseQueryString
|
|||||||||||||||
|
HttpUtility.ParseQueryString will work as long as you are in a web app or don't mind including a dependency on System.Web. Another way to do this is:
|
|||||
|
I wanted to remove the dependency on System.Web so that I could parse the query string of a ClickOnce deployment, while having the prerequisites limited to the "Client-only Framework Subset". I liked rp's answer. I added some additional logic.
|
|||
|
Just access Request.QueryString. AllKeys mentioned as another answer just gets you an array of keys. |
|||
|
Hit up Request.QueryString.Keys for a NameValueCollection of all query string parameters. |
|||
|
|
|||||||||
|
|
||||
|