2

I have a url string that I want to encode before passing it as an argument to the browser. I'm used the "HttpUtility.UrlEncode" function but found out that it doesn't encode all the URL, it doesn't take the query param.

For Example:

string url = "http://www.google.com?A --chrome-frame"

This function will not encode the space char after the parameter.

The "Uri.EscapeUriString" will encode the spacing but will it encode all other character that the "UrlEncode" function encode?, Note that I can't use them both because this will break the URL.

Does:

string encodeUrl = Uri.EscapeUriString(url);

Is equivalent to:

Uri uriObject = new Uri(url);
string encodeUrl = uriObject.AbsoluteUri;

Do you have other suggestions?

*Note that its not duplicate of "Server.UrlEncode vs. HttpUtility.UrlEncode" :)

Thanks

Aviram Fireberger
  • 3,910
  • 5
  • 50
  • 69

0 Answers0