querystring parameters

C

Cowboy (Gregory A. Beamer)

Hi all,

If I am reading this right, then the querystring parameters must be
"&" and not "&". However, IIS 6.0 and asp.net request.querystring
fails to capture the values if "&" is specified. e.g.
http://myserver/test.aspx?pid=1&did=2

http://www.w3.org/TR/html401/appendix/notes.html#h-B.2.2

Any ideas?

QueryString parameters are separated by &, not &amp. If you have an
ampersandin a variale, it must be &. If you use ampersands ina
variable, you have to unencode afterwards.
 
S

Steven Cheng[MSFT]

Thanks for Gregory's input.

Hello Param,

I think this problem you met is related to the html url encoding.

Yes, you're right that there are some particular characters that must be
encoded when being embeded in url string(in the querystring value). This
is because there are some chars which has their reserved usage. for
example, as a typical url with querystring as below:

http://website/app/test.aspx?id=xxxx&name=xxxx

The "&" and "=" character has their particular usage in querystring (to
separate multi querystring items and separate key and value of each item).
Thus, when such characters occur in our querystring item's value, we need
to escape them.

However, the escape format for url string is not like the one you
mentioned:

&---> & (this is used in XML/HTML document's character escaping)

but like:

&----> %26

because URL encoding rule will escape the original characeter to their hex
value (with a % preceding ). So for the above example, if the "name"
parameter's value contains a "&" char, the escaped (after url encoding) url
will look like:

http://website/app/test.aspx?id=xxxx&name=xx&xx

Here is an article introducing url encoding

#INTRODUCTION TO URL ENCODING
http://www.permadi.com/tutorial/urlEncoding/

#HTML URL-encoding Reference
http://www.w3schools.com/tags/ref_urlencode.asp

Actually, you can even url encode every ascii char in the querystring value
(through this is not necessary). For example, if you use the following url

http:/....../urlstringpage.aspx?name=%26%41%42%43

the server-side component (such as ASP.NET ) can correct decode the value
and get the original querystring:

name= &ABC



If there is anything unclear, please feel free to let me know.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Steve, I understand what u r trying to say. So why does this article say
otherwise:

http://www.w3.org/TR/html401/appendix/notes.html#h-B.2.2

Clearly it shows and recommends using "&" as the querystring item
seperator.

Am I missing something? I have a 3rd party partner that is trying to link
into our system and will not budge on this. He claims that he is standards
compliant, but the link doesnt work on my end i.e. my .aspx can never
retrieve his url parameters.

TIA!
 
S

Steven Cheng[MSFT]

Thanks for your quick reply Param,

Yes, the document you refered is correct, and actually what the document
stated and what I mentioend in the last reply aims at different context.
The W3C document you refer to is targeting the "&" character in a SGML or
(commonly a xml/html document). That means, when we put a url in an
SGML/XML/HTML document and the document contains "&" in the url
querystring, you can either use "&" directly or use the "&" format.

For html web page, if you use the following style url:

<A href="http://host/?x=1&amp;y=2">

the webbrowser will help you translate it into the following one when send
http request to the linked resource:

http://host/?x=1&y=2

so in http request message, the querystring separater must be "&" (hex
value 26) rather than "&amp;"

"&amp;" is used in html page's content only. You can also use some TCP or
http trace utility to capture the http request message to verfiy this.

In other word, in html/xhtml webpage, you can use either "&amp;" or "&" as
the querystring separater, however, if you directly input the url in
browser's address bar or use other network component to send http request,
you should use "&" for querystring separator(or the %26 urlencoded
format) rather than the "&amp;" style.

Hope this clarify it further. Please feel free to let me know if you have
any other questions.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top