在 SignalR 集线器中检查可选 header
Checking for an optional header in a SignalR hub
在 SignalR 集线器方法中,Context.Headers
提供 INameValueCollection
请求 header。 INameValueCollection
只有三个成员:
string this[string key] { get; }
string Get(string key);
IEnumerable<string> GetValues(string key);
不幸的是,其中 none 个已记录在案。如果你想获得一个 header 但如果它不存在则不抛出异常,你使用什么?我猜 Get
,但如果作者愿意记录这些细节,那肯定会很好。
我喜欢 "old" Microsoft 的一件事是,即使有点冗长,它的文档也涵盖了几乎所有的语义。 SignalR 是一个很棒的、快速的开发,但如果它能保持 old-school 的勤奋,那就更好了。
也许我遗漏了什么。语义是否记录在某处?或者有人知道并愿意将它们记录在这里作为一种快速而肮脏的解决方法吗?
有同样的问题,最后我在the github source which takes you System.Collections.Specialized.NameValueCollection
中查找了它
(还有 INameValueCollection
的其他实现,但链接的那个似乎在请求中使用)
简而言之:
string this[string key] { get; }
string Get(string key);
A String that contains the comma-separated list of values associated with the specified key, if found; otherwise, null.
IEnumerable<string> GetValues(string key);
A String array that contains the values associated with the specified key from the NameValueCollection, if found; otherwise, null.
在 SignalR 集线器方法中,Context.Headers
提供 INameValueCollection
请求 header。 INameValueCollection
只有三个成员:
string this[string key] { get; }
string Get(string key);
IEnumerable<string> GetValues(string key);
不幸的是,其中 none 个已记录在案。如果你想获得一个 header 但如果它不存在则不抛出异常,你使用什么?我猜 Get
,但如果作者愿意记录这些细节,那肯定会很好。
我喜欢 "old" Microsoft 的一件事是,即使有点冗长,它的文档也涵盖了几乎所有的语义。 SignalR 是一个很棒的、快速的开发,但如果它能保持 old-school 的勤奋,那就更好了。
也许我遗漏了什么。语义是否记录在某处?或者有人知道并愿意将它们记录在这里作为一种快速而肮脏的解决方法吗?
有同样的问题,最后我在the github source which takes you System.Collections.Specialized.NameValueCollection
中查找了它(还有 INameValueCollection
的其他实现,但链接的那个似乎在请求中使用)
简而言之:
string this[string key] { get; }
string Get(string key);
A String that contains the comma-separated list of values associated with the specified key, if found; otherwise, null.
IEnumerable<string> GetValues(string key);
A String array that contains the values associated with the specified key from the NameValueCollection, if found; otherwise, null.