Server.UrlEncode & Server.UrlDecode

asp.net, c#

Solution

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 ...

Server.URLEncode

HttpServerUtility.UrlDecode

Problem

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?

Original source