I don't know, Why do we use Server.UrlEncode() & Server.UrlDecode()?!
in QueryString we see anything in URL, so why do we want encode or decode them?
3 Answers 3
The URLEncode method applies URL encoding rules, including escape characters, to a specified string.
URLEncode converts characters as follows:
Spaces ( ) are converted to plus signs (+).
Non-alphanumeric characters are escaped to their hexadecimal representation.
Also, I think you are talking about HttpServerUtility.UrlDecode method which decodes the encoded string and returnes you back the original string.
URL-decodes a string and returns the decoded string
URL encoding ensures that all browsers will correctly transmit text in URL strings. Characters such as a question mark (?), ampersand (&), slash mark (/), and spaces might be truncated or corrupted by some browsers. As a result, these characters must be encoded in tags or in query strings where the strings can be re-sent by a browser in a request string.
UrlDecode is a convenient way to access the HttpUtility.UrlDecode method at run time from an ASP.NET application. Internally, UrlDecode uses HttpUtility.UrlDecode to decode strings.
More info ...
Comments
URLEncode converts characters as follows:
Spaces ( ) are converted to plus signs (+). Non-alphanumeric characters are escaped to their hexadecimal representation.
<%Response.Write(Server.URLEncode("http://www.microsoft.com")) %>
produces the following output:
http%3A%2F%2Fwww%2Emicrosoft%2Ecom