I always use OriginalString since I ran into several problems with AbsoluteUri . Namely:
AbsoluteUri behaves differently in .NET 4.0 vs .NET 4.5 ( see )
.NET Framework 4.0
var uri = new Uri("http://www.example.com/test%2F1"); Console.WriteLine(uri.OriginalString); // http://www.example.com/test%2F1 Console.WriteLine(uri.AbsoluteUri); // http://www.example.com/test/1 <-- WRONG
.NET Framework 4.5
var uri = new Uri("http://www.example.com/test%2F1"); Console.WriteLine(uri.OriginalString); // http://www.example.com/test%2F1 Console.WriteLine(uri.AbsoluteUri); // http://www.example.com/test%2F1
AbsoluteUri does not support relative URIs
var uri = new Uri("/test.aspx?v=hello world", UriKind.Relative); Console.WriteLine(uri.OriginalString); // /test.aspx?v=hello world Console.WriteLine(uri.AbsoluteUri); // InvalidOperationException: This operation is not supported for a relative URI.
AbsoluteUri does unwanted shielding
var uri = new Uri("http://www.example.com/test.aspx?v=hello world"); Console.WriteLine(uri.OriginalString); // http://www.example.com/test.aspx?v=hello world Console.WriteLine(uri.AbsoluteUri); // http://www.example.com/test.aspx?v=hello%20world <-- WRONG
source share