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 = " --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” 🙂


Source: .net

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.