All of these methods are relative to RFC 2396
, which defines the Uniform Resource Identifiers (URI) syntax and, in the case of UrlEncode, also the RFC 1738
(which defines Uniform Resource Locators , or URLs).
UrlEncode
When to use : When you need to ensure that a URL is valid, or when you need to pass a URL as a parameter within another URL. How it works : Converts all the reserved or control characters defined in the
RFC 1738
to their encoded equivalents, thus avoiding markers such as white space (which could define the end of a resource's name) or the backslash (which could define a protocol or credentials depending on the position) are erroneously interpreted.
EscapeUriString
When to use : When you need to pass a URI instead of a URL. How it works : Converts all characters (except those described as non-reserved in RFC 2396
) for hexadecimal representation. (this behavior changes if IRIs or IDN interpretation is enabled). Because the character set reserved for URIs differs from the set for URLs, some valid URLs may be misinterpreted (especially with the use of the plus sign.)
EscapeDataString
When to use : When you need to pass data in a URI. How it works : Performs the same transformations as
EscapeUriString
, but includes control characters considered valid to a URI in the conversion in order to allow the data to be correctly interpreted as content rather than identifiers.
You can find some conversion tables between formats here .