HttpUtility.UrlEncode vs Uri.EscapeUriString in .NET

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.

Do you have other suggestions?

*Note that its not duplicate of “Server.UrlEncode vs. HttpUtility.UrlEncode” 🙂

Thanks


Source: .net

Leave a Reply