What's the difference between Uri.ToString() and Uri.AbsoluteUri?

前端 未结 5 925
情书的邮戳
情书的邮戳 2020-12-14 13:43

As a comment to an Azure question just now, @smarx noted

I think it\'s generally better to do blob.Uri.AbsoluteUri than blob.Uri.ToString().

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-14 14:08

    Since everybody seems to think that uri.AbsoluteUri is better, but because it fails with relative paths, then probably the universal way would be:

    Uri uri = new Uri("fuu/bar.xyz", UriKind.Relative);
    string notCorruptUri = Uri.EscapeUriString(uri.ToString());
    

提交回复
热议问题