System.Uri
has Host
, Authority
, and DnsSafeHost
. MS provides a nice example of when Host
and DnsSafeHost
are different here.
I'd like a similar example/explanation for Host
and Authority
.
System.Uri
has Host
, Authority
, and DnsSafeHost
. MS provides a nice example of when Host
and DnsSafeHost
are different here.
I'd like a similar example/explanation for Host
and Authority
.
For the Uri class in .NET, Authority includes the port, Host does not, and neither includes user information.
Some examples of valid URIs:
According to RFC3986, Section 3.2 the Authority contains
NOT just host and port number.
For example, the following is a valid URI:
in which the Authority is
The at symbol (@) delimits the user info from the host and the colon (:) delimits the host from the port number. Within the user info, a colon (:) delimits the username from the password. (Yes, I know the password portion is deprecated. It may still optionally be supported.)
This is the full spec for an Authority. Obviously, the user info and port number are often not present.
The Uri class in .NET drops the user information when returning the Authority which is rather annoying because it's not correct. Instead you can find the user info in the UserInfo property:
Other answers are technically correct to say that for the .NET Uri class that the difference between Uri.Authority and Uri.Host is that the host will not contain a port number.
But please know that Authority is not properly defined the way it is used in the .NET Uri class because it may also contain user info.
Every HTTP URL conforms to the syntax of a generic URI. The URI generic syntax consists of a hierarchical sequence of five components:
where the authority component divides into three subcomponents:
Like this:
An optional authority component preceded by two slashes (//), comprising:
For more details, you can refer to https://en.wikipedia.org/wiki/URL .
According to the documentation you linked to, the
Authority
property will include the port number if it is not the same as the default port of the Uri, while theHost
property will only return the DNS Host name or IP Address.I don't believe there are any more differences than that.
Yes Brandon is absolutely correct, in layman terms
Authority = Host Name + Port No
And if URL protocol is using a default port, say port 80 for http URL, then only in that case Authority = Host Name (Port No is assumed to be 80),
Whereas Host Name is either Domain Name or I.P Address
Example:
http://www.example.com/
Authority = www.example.com
Host Name = www.example.com
http://255.255.255.255:8080/
Authority = 255.255.255.255:8080
Host Name = 255.255.255.255
From MSDN URI.Host page.
Authority can also include a username and password, e.g.
bob:pwd@somewhere.example.com
more commonly used for FTP URIs