The Query String

The query string is handled differently from the rest of the virtual path. It is neither URL decoded or case-normalized before it reaches ASP.NET, although each name-value pair is URL decoded before being stored in the Request.QueryString collection. For the query string to be parsed correctly, the delimiters ?, &, and = cannot be percent-encoded. Both names and values in the Request.QueryString collection go through exactly one URLDecode pass. Other properties in the Request class include the querystring in its original, URLEncoded form (if they were originally URL (percent) encoded). Also, any strings that aren't parsed correctly are added to Request.QueryString[null] in comma-delimited format. (You can also access them as a string[] array using Request.QueryString.GetValues(null)). The NameValueCollection class isn't a string-to-string dictionary. It's more like an informal string-to-string[] dictionary. When you set a value like nvc["thiskey"]="thisvalue" , you are in overwrite mode. When you use nvc.add("thiskey","thisvalue"), you are in append mode. Calling nvc.add("thiskey","firstvalue"), then nvc.add("thiskey","lastvalue") will leave nvc["thiskey"] == "firstvalue,lastvalue".

Related links

Published on

About Nathanael

Nathanael Jones is a software engineer, father, consultant, and computer linguist with unreasonably high expectations of inanimate objects. He refines .NET, ruby, and javascript libraries full-time at Imazen, but can often be found on stack overflow or participating in W3C community groups.

ImageResizer

If you develop websites, and those websites have images, ImageResizer can make your life much eaiser. Find out more at imageresizing.net.

Imazen

I run Imazen, a tiny software company that specializes in web-based image processing and other difficult engineering problems. I spend most of my time writing image-processing code in C#, web apps in Ruby, and documentation in Markdown. Check out some of my current projects.

More articles