Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

.net

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().

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."

like image 630
Jeremy McGee Avatar asked Oct 02 '11 06:10

Jeremy McGee


People also ask

What is AbsoluteUri?

The AbsoluteUri property includes the entire URI stored in the Uri instance, including all fragments and query strings.

What is absolute path in URI?

The AbsolutePath property contains the path information that the server uses to resolve requests for information. Typically this is the path to the desired information on the server's file system, although it also can indicate the application or script the server must run to provide the information.

What is Uri in asp net?

A URI is a compact representation of a resource available to your application on the intranet or internet. The Uri class defines the properties and methods for handling URIs, including parsing, comparing, and combining. The Uri class properties are read-only; to create a modifiable object, use the UriBuilder class.


1 Answers

Given for example:

UriBuilder builder = new UriBuilder("http://somehost/somepath"); builder.Query = "somekey=" + HttpUtility.UrlEncode("some+value"); Uri someUri = builder.Uri; 

In this case, Uri.ToString() will return a human-readable URL: http://somehost/somepath?somekey=some+value

Uri.AbsoluteUri on the other hand will return the encoded form as HttpUtility.UrlEncode returned it: http://somehost/somepath?somekey=some%2bvalue

like image 69
Ofer Zelig Avatar answered Sep 30 '22 23:09

Ofer Zelig