UriBuilder builder = new UriBuilder("http://somehost/somepath");
builder.Query = "somekey=" + HttpUtility.UrlEncode("some+value");
Uri someUri = builder.Uri;
Response.Write("<p>" + someUri.AbsoluteUri + "</p>");
Response.Write("<p>" + someUri.ToString() + "</p>");
显示的结果如下:
http://somehost/somepath?somekey=some%2bvalue
http://somehost/somepath?somekey=some+value
也就是说:如果要在浏览器中传送这个 Uri,则使用 AbsoluteUri;如果要获得未编码的 Uri,则使用 ToString()。