爲什麼thirdRelativeUri失敗?這是一個.NET錯誤?似乎不是在4.0中修復的。Uri構造函數.NET Framework錯誤?
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.
UPDATE:
@dariom指出,這是因爲協議相對URL在.NET處理這道理然而,這似乎仍然越野車對我說:
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
它失敗即使當第二個Uri是Relative
爲什麼你通過「///test.htm」而不是「//test.htm」? –
@DavidePiras因爲我邪惡?我需要提出以下要求:http://example.com///test.htm在一個完美的世界example.com/test.htm和example.com ///test.htm沒有區別,但真正的Web服務器和框架不幸是瘋了,有成千上萬。 –
我同意@ dr.evil。解析應接受無用的目錄/路徑分隔符。 – leppie