Uri.Host 和 Uri.Authority 之间有什么区别
System.Uri
具有 Host
、Authority
和 DnsSafeHost
。 MS 提供了一个很好的示例,说明 Host
和 DnsSafeHost
何时不同此处。
我想要 Host
和 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
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
是的,布兰登是绝对正确的,用外行人的话说,
权限=主机名+端口号
,如果URL协议使用默认端口,比如http URL的端口80,那么只有在这种情况下
权限 = 主机名(假设端口号为 80),
而主机名可以是域名或 IP 地址
示例:
http://www.example.com/< /代码>
权限 = www.example.com
主机名= www.example.com
http://255.255.255.255:8080/
权限= 255.255.255.255:8080
主机名 = 255.255.255.255
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
来自 MSDN URI.Host 页面。
From MSDN URI.Host page.
每个 HTTP URL 都符合通用 URI 的语法。 URI 通用语法由五个组件的分层序列组成:
其中 authority 组件分为三个子组件:
像这样:
一个可选的 authority 组件,前面有两个斜杠 (//),包括:
欲了解更多详情,您可以参考https://en.wikipedia.org/wiki/URL 。
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 .
对于.NET中的Uri类,Authority包含端口,Host不包含端口,也不包含用户信息。
有效 URI 的一些示例:
根据 RFC3986,第 3.2 节 授权机构包含
不仅仅是主机和端口号。
例如,以下是有效的 URI:
其中权限为
at 符号 (@) 将用户信息与主机分隔开,冒号 (:) 将主机与端口号分隔开。在用户信息中,冒号 (:) 将用户名与密码分隔开。 (是的,我知道密码部分已被弃用。它仍然可以选择支持。)
这是权威的完整规范。显然,用户信息和端口号通常不存在。
.NET 中的 Uri 类在返回权限时会删除用户信息,这是相当烦人的,因为它不正确。相反,您可以在 UserInfo 属性中找到用户信息:
其他答案在技术上是正确的,即 对于 .NET Uri 类 Uri.Authority 和 Uri 之间的差异。 Host是主机不会包含端口号。
但请注意,Authority 未按照在 .NET Uri 类中使用的方式正确定义,因为它还可能包含用户信息。
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.
根据您链接到的文档,如果
Authority
属性与 Uri 的默认端口不同,则该属性将包含端口号,而Host
属性仅包含端口号返回 DNS 主机名或 IP 地址。我认为没有比这更多的差异了。
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.
权限还可以包含用户名和密码,例如
bob:[电子邮件受保护]
更常用于 FTP URI
Authority can also include a username and password, e.g.
bob:[email protected]
more commonly used for FTP URIs