System.Uri
has Host
, Authority
, and DnsSafeHost
. MS provides a nice example of when Host
and DnsSafeHost
are different here.
系统。Uri有主机、权限和DnsSafeHost。MS提供了一个很好的例子,当主机和DnsSafeHost在这里是不同的。
I'd like a similar example/explanation for Host
and Authority
.
我想给主持人和权威一个类似的例子/解释。
5 个解决方案
#1
48
Yes Brandon is absolutely correct, in layman terms
是的,布兰登绝对是正确的。
Authority = Host Name + Port No
权限=主机名+端口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),
如果URL协议使用默认端口,比如http URL的端口80,那么只有在这个case Authority =主机名(端口No被假设为80),
Whereas Host Name is either Domain Name or I.P Address
而主机名不是域名就是我。P地址
Example:
例子:
-
http://www.example.com/
Authority = www.example.com
Host Name = www.example.comhttp://www.example.com/ Authority = www.example.com。
-
http://255.255.255.255:8080/
http://255.255.255.255:8080
Authority = 255.255.255.255:8080
Host Name = 255.255.255.255主机名= 255.255.255.255:8080主机名= 255.255.255.255。
#2
32
From MSDN URI.Host page.
从MSDN URI。主机页面。
Unlike the Authority property, this property value does not include the port number.
与权限属性不同,此属性值不包含端口号。
#3
8
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 the Host
property will only return the DNS Host name or IP Address.
根据您链接到的文档,权限属性将包括端口号,如果它不与Uri的默认端口相同,而主机属性只返回DNS主机名或IP地址。
I don't believe there are any more differences than that.
我不认为还有什么不同。
#4
5
For the Uri class in .NET, Authority includes the port, Host does not, and neither includes user information.
对于。net中的Uri类,权限包括端口,主机不包含,也不包括用户信息。
Some examples of valid URIs:
一些有效的uri示例:
Uri u = new Uri("http://www.domain.com/path");
Assert.AreEqual("www.domain.com", u.Authority);
Assert.AreEqual("www.domain.com", u.Host);
Assert.AreEqual("http://www.domain.com", u.GetLeftPart(UriPartial.Authority));
u = new Uri("http://www.domain.com:8080/path");
Assert.AreEqual("www.domain.com:8080", u.Authority);
Assert.AreEqual("www.domain.com", u.Host);
Assert.AreEqual("http://www.domain.com:8080", u.GetLeftPart(UriPartial.Authority));
u = new Uri("http://user:password@host:555/path");
Assert.AreEqual("host:555", u.Authority);
Assert.AreEqual("host", u.Host);
Assert.AreEqual("http://user:password@host:555", u.GetLeftPart(UriPartial.Authority));
According to RFC3986, Section 3.2 the Authority contains
根据RFC3986,第3.2节授权包含。
- User Information
- 用户信息
- Host
- 主机
- Port number.
- 端口号。
NOT just host and port number.
不只是主机和端口号。
For example, the following is a valid URI:
例如,下面是一个有效的URI:
http://user:password@host:80/path
in which the Authority is
在其中的权威。
user:password@host:80
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.)
at符号(@)将用户信息从主机和冒号(:)中分离出来,并将主机从端口号中分离出来。在用户信息中,冒号(:)将用户名从密码中删除。(是的,我知道密码部分被弃用了。它仍然可以选择被支持。
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:
. net中的Uri类在返回权限时降低了用户信息,这很烦人,因为它不正确。相反,您可以在UserInfo属性中找到用户信息:
Uri.UserInfo
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.
其他的答案在技术上是正确的,对于。net Uri类来说,Uri之间的区别。权威和Uri。主机是主机不包含端口号。
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.
但是,请知道,在. net Uri类中,权限的定义并不正确,因为它可能还包含用户信息。
#5
0
Authority can also include a username and password, e.g.
权限还可以包括用户名和密码。
bob:pwd@somewhere.example.com
鲍勃:pwd@somewhere.example.com
more commonly used for FTP URIs
更常用的FTP uri。
#1
48
Yes Brandon is absolutely correct, in layman terms
是的,布兰登绝对是正确的。
Authority = Host Name + Port No
权限=主机名+端口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),
如果URL协议使用默认端口,比如http URL的端口80,那么只有在这个case Authority =主机名(端口No被假设为80),
Whereas Host Name is either Domain Name or I.P Address
而主机名不是域名就是我。P地址
Example:
例子:
-
http://www.example.com/
Authority = www.example.com
Host Name = www.example.comhttp://www.example.com/ Authority = www.example.com。
-
http://255.255.255.255:8080/
http://255.255.255.255:8080
Authority = 255.255.255.255:8080
Host Name = 255.255.255.255主机名= 255.255.255.255:8080主机名= 255.255.255.255。
#2
32
From MSDN URI.Host page.
从MSDN URI。主机页面。
Unlike the Authority property, this property value does not include the port number.
与权限属性不同,此属性值不包含端口号。
#3
8
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 the Host
property will only return the DNS Host name or IP Address.
根据您链接到的文档,权限属性将包括端口号,如果它不与Uri的默认端口相同,而主机属性只返回DNS主机名或IP地址。
I don't believe there are any more differences than that.
我不认为还有什么不同。
#4
5
For the Uri class in .NET, Authority includes the port, Host does not, and neither includes user information.
对于。net中的Uri类,权限包括端口,主机不包含,也不包括用户信息。
Some examples of valid URIs:
一些有效的uri示例:
Uri u = new Uri("http://www.domain.com/path");
Assert.AreEqual("www.domain.com", u.Authority);
Assert.AreEqual("www.domain.com", u.Host);
Assert.AreEqual("http://www.domain.com", u.GetLeftPart(UriPartial.Authority));
u = new Uri("http://www.domain.com:8080/path");
Assert.AreEqual("www.domain.com:8080", u.Authority);
Assert.AreEqual("www.domain.com", u.Host);
Assert.AreEqual("http://www.domain.com:8080", u.GetLeftPart(UriPartial.Authority));
u = new Uri("http://user:password@host:555/path");
Assert.AreEqual("host:555", u.Authority);
Assert.AreEqual("host", u.Host);
Assert.AreEqual("http://user:password@host:555", u.GetLeftPart(UriPartial.Authority));
According to RFC3986, Section 3.2 the Authority contains
根据RFC3986,第3.2节授权包含。
- User Information
- 用户信息
- Host
- 主机
- Port number.
- 端口号。
NOT just host and port number.
不只是主机和端口号。
For example, the following is a valid URI:
例如,下面是一个有效的URI:
http://user:password@host:80/path
in which the Authority is
在其中的权威。
user:password@host:80
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.)
at符号(@)将用户信息从主机和冒号(:)中分离出来,并将主机从端口号中分离出来。在用户信息中,冒号(:)将用户名从密码中删除。(是的,我知道密码部分被弃用了。它仍然可以选择被支持。
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:
. net中的Uri类在返回权限时降低了用户信息,这很烦人,因为它不正确。相反,您可以在UserInfo属性中找到用户信息:
Uri.UserInfo
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.
其他的答案在技术上是正确的,对于。net Uri类来说,Uri之间的区别。权威和Uri。主机是主机不包含端口号。
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.
但是,请知道,在. net Uri类中,权限的定义并不正确,因为它可能还包含用户信息。
#5
0
Authority can also include a username and password, e.g.
权限还可以包括用户名和密码。
bob:pwd@somewhere.example.com
鲍勃:pwd@somewhere.example.com
more commonly used for FTP URIs
更常用的FTP uri。