I am using .NET 3.5.
Both solutions which are described here (the property "genericUriParserOptions"
in config file and constructor parameter "dontEscape"
) don't work for .NET 3.5.
I want that URI
constructor doesn't escape (means I want to have escaped URL
parts) anything. Now I can't use configuration file with
genericUriParserOptions="DontUnescapePathDotsAndSlashes"
bacause this property is only available for .NET 4.0. But I can't also use "dontEscape"
parameter in URI
constructor because the constructor is obsolete in .NET 3.5 and is always false
.
How I can create an URI
with escaped string in .NET 3.5?
You should encode only the user name or other part of the URL that could be invalid. URL encoding a URL can lead to problems since something like this:
string url = HttpUtility.UrlEncode("http://www.google.com/search?q=Example");
Will yield
http%3a%2f%2fwww.google.com%2fsearch%3fq%3dExample
This is obviously not going to work well. Instead, you should encode ONLY the value of the key/value pair in the query string, like this:
string url = "http://www.google.com/search?q=" + HttpUtility.UrlEncode("Example");
Thanks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With