为什么thirdRelativeUri失败了?这是一个.NET错误吗?似乎也没有在4.0中修复.
var googleU = new Uri("http://www.google.com");
var secondRelativeUri = new Uri(googleU,"//test.htm"); // doesn't fail
var thirdRelativeUri = new Uri(googleU,"///test.htm"); // fails - Invalid URI: The hostname could not be parsed.
Run Code Online (Sandbox Code Playgroud)
更新:
@dariom指出这是因为.NET中的协议相对URL处理有意义但是这对我来说仍然是错误的:
var thirdRelativeUri = new Uri("///test.htm",UriKind.Relative); // works as expected
var newUri = new Uri(googleU,thirdRelativeUri); //Fails, same error even though it's a relative URI
Run Code Online (Sandbox Code Playgroud)
即使是第二个Uri,它也会失败 Relative