2

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?

asked May 18, 2012 at 14:00

3 Answers 3

6

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

answered May 18, 2012 at 14:08
Sign up to request clarification or add additional context in comments.

Comments

2

It is taken from here

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 
answered May 18, 2012 at 14:08

1 Comment

Mesut Darvishian you are Welcome.
0

Some characters are not legal in URLs, so they must be encoded. This was the first hit I found for a list of illegal characters.

answered May 18, 2012 at 14:04

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.