什么是Uri.ToString()和Uri.AbsoluteUri之间的区别? [英] What's the difference between Uri.ToString() and Uri.AbsoluteUri?
问题描述
作为注释到Azure的问题,就在刚才,@smarx指出
As a comment to an Azure question just now, @smarx noted
我认为这是一般好做blob.Uri.AbsoluteUri比 blob.Uri.ToString()。
I think it's generally better to do blob.Uri.AbsoluteUri than blob.Uri.ToString().
有没有道理呢?该文档 Uri.AbsoluteUri
指出,它获取绝对URI, Uri.ToString()
获取规范的字符串重新presentation指定实例。
Is there a reason for this? The documentation for Uri.AbsoluteUri
notes that it "Gets the absolute URI", Uri.ToString()
"Gets a canonical string representation for the specified instance."
推荐答案
鉴于例如:
UriBuilder builder = new UriBuilder("http://somehost/somepath");
builder.Query = "somekey=" + HttpUtility.UrlEncode("some+value");
Uri someUri = builder.Uri;
在这种情况下,
Uri.ToString()
将返回一个人类可读的网址:<一href="http://somehost/somepath?somekey=some+value">http://somehost/somepath?somekey=some+value
In this case,
Uri.ToString()
will return a human-readable URL: http://somehost/somepath?somekey=some+value
Uri.AbsoluteUri
,另一方面将返回EN codeD形式HttpUtility.UrlEn code还给了: HTTP ://,某/ somepath somekey =某些%2bvalue
Uri.AbsoluteUri
on the other hand will return the encoded form as HttpUtility.UrlEncode returned it: http://somehost/somepath?somekey=some%2bvalue
这篇关于什么是Uri.ToString()和Uri.AbsoluteUri之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!