SignalR 不使用服务器上的会话
当我尝试从 HUB 访问 HttpContext
当前会话时,它返回 null
。
我尝试使用接口 IRequiresSession
但它不起作用。有人可以帮助我吗?
When I try to access the HttpContext
current session from the HUB it returns null
.
I tried making use of the interface IRequiresSession
but it didn't work. Can someone help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
SignalR 连接(包括客户端所有 Hub 操作的底层连接)不支持会话状态。如果您愿意,您可以启用它,但我们强烈建议您不要使用它,因为会话状态访问会序列化给定客户端的请求,这意味着您将不再真正从 SignalR 双工消息传递中受益,因为一个请求将阻止另一个请求,例如在长轮询传输中,接收连接将阻止任何发送尝试。
SignalR connections (including the connection underlying all Hub operations for a client) do not support Session state. You could enable it if you wanted to but we'd strongly recommend against it as session state access serializes requests for a given client, meaning you won't really get the benefit from SignalR duplex messaging anymore, as one request will block the other e.g. in the long polling transport, the receiving connection will block any attempt to send.
你可以简单地维护自己的会话,例如,在内存缓存中使用,http是无状态的,所以服务器需要会话来维护客户端,但Web套接字是保活连接,服务器与客户端保持连接,默认情况下不需要这样的东西HttpContext 会话。
you can simply maintain your own session, for example, use in memory cache, http is stateless,so server need session to maintain clients,but web socket is keep-alive connection, server keeps connected with clients, by default no need such things like HttpContext Session.
我解决了隐藏字段的相同问题,如下所示:
I resolve the same problem with hidden field as follows: