なぜ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.
更新:
@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
It fails even when the second Uri is Relative
ベストアンサー
ファイルURIスキーム(RFC 1738)ファイル:// [host]/pathは、ホストがオプションであることを示しています。
///test.htmlは “これは通常ローカルファイルに使用されるため、RFC
1738のホストは空であることが多く、開始トリプル/。(ref)“
/// test.htm を
file:///test.htm に変更すると、URIコンストラクタが正しく解析します。
AbsolutePath
は /test.html です。
お役に立てれば。