Eugene D. Gubenkov Eugene D. Gubenkov - 1 year ago 73
C# Question

.NET Uri.ToString() ruins the URL?

I've noticed that if you call

when URI behind is URL with percent encoded spaces (%20), then you will have malformed URL as the result:

// result: " segment"
new Uri("").ToString();

Since URL is URI (opposite statement is not correct) and URL with non encoded spaces is not valid it looks like it's not safe to use Uri as the container for URL.

Is it correct behaviour?

Answer Source

As per MSDN:

// result: " segment"
new Uri("").ToString();

// result: ""
new Uri("").OriginalString;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download