Is it bad to use special symbols in URL?
Context: ASP.NET MVC 2.0
I want to support URL of following format:
wowreforge.com?Exp=220,Hit<461,Mastery>Haste>Crit
It works in both FF and IE. They both escape symbols correctly when entered.
My question: are there any reasons not to use the URL-form above?
Background
I want 开发者_StackOverflow社区the URL to be usable as a general formula that you can paste in a thread discussion, or instant message. Something like:I think that for combat rogue wowreforge.com?Exp=220,Hit<461,Mastery>Haste>Crit is the best reforging strategy.
Any alternative implementation ideas are welcome.
You should always run such values through your web framework's URL Encode function. Such functions will encode values which need to be encoded, and not encode those which do not.
This is better than trying to guess which characters are OK in a query string and which are not.
Also note that you should apply this encoding on the values of each query string parameter - not on the entire query string itself. (otherwise you would end up improperly encoding the ampersand that splits parameters, for example)
<
and >
are not allowed in a URL and must be encoded with the percent-encoding.
But besides that there is a difference between how browser display URLs and how they are actually encoded. For example, modern browsers display sequences of percent-encoded words that represent characters in UTF-8 as the characters they represent rather than the encoded words. So a URL like http://en.wikipedia.org/wiki/%C3%9F
is often displayed as http://en.wikipedia.org/wiki/ß
although it is actually encoded as http://en.wikipedia.org/wiki/%C3%9F
.
RFC 1738 says this is a bad idea:
"...Only alphanumerics [0-9a-zA-Z], the special characters "$-_.+!*'()," [not including the quotes - ed], and reserved characters used for their reserved purposes may be used unencoded within a URL."
Try encoding all of the special characters using the ASCII control codes. This is the safe way to send special characters via a URL.
精彩评论