I keep hearing that W3C recommends to use “;” instead of “&” as a query string separator.
We recommend that HTTP server implementors, and in particular, CGI
implementors support the use of “;” in place of “&” to save authors
the trouble of escaping “&” characters in this manner.
Can somebody please explain why “;” is recommended instead of “&”?
Also, i tried using ";" instead of "&". (example: .com?str1=val1;str2=val2 ) . When reading as Request.QueryString["str1"] i get “val1;str2=val2“. So if ";" is recommended, how do we read the query strings?
As the linked document says,
;is recommended over&becauseFor example, say you want your URL to be
...?q1=v1&q2=v2There’s nothing wrong with
&there. But if you want to put that query into an HTML attribute,<a href="...?q1=v1&q2=v2">, it breaks because, inside an HTML attribute,&represents the start of a character entity. You have to escape the&as&, giving<a href="...?q1=v1&q2=v2">, and it’d be easier if you didn’t have to.;isn’t overloaded like this at all; you can put one in an HTML attribute and not worry about it. Thus it’d be much simpler if servers recognised;as a query parameter separator.However, by the look of things (based on your experiment), ASP.Net doesn’t recognise it as such. How to get it to? I’m not sure you can.