在 SignalR 集线器方法中,Context.Headers
提供带有请求 header 的 INameValueCollection
。 INameValueCollection
只有三个成员:
string this[string key] { get; }
string Get(string key);
IEnumerable<string> GetValues(string key);
不幸的是,这些都没有被记录下来。如果你想获取一个 header ,但如果它不存在则不抛出异常,你会使用什么?我猜是 Get
,但如果作者能费心记录这些细节,那就太好了。
我喜欢“老”微软的一件事是,即使有点冗长,它的文档几乎涵盖了所有语义。 SignalR 是一个美妙、快速的开发,但如果它保留了老式的勤奋那就更好了。
也许我错过了一些东西。语义是否记录在某处?或者是否有人知道并愿意将它们记录在这里作为一种快速而肮脏的解决方法?
最佳答案
遇到了同样的问题,最后我在 the github source 中查找了它这会带你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.
关于http-headers - 检查 SignalR 集线器中的可选 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31492986/