没有获得通过SignalR集线器的会话信息

没有获得通过SignalR集线器的会话信息

本文介绍了没有获得通过SignalR集线器的会话信息。是我设计的是错的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚发现你不能在SignalR中心内访问当前会话。

I've just discovered you can't access the current session within the SignalR Hub.

简化我的情况:我试图写一个聊天

Simplified my scenario: I've tried to write a chat.

当前用户的名称保持在会话中。

The name of the current user was kept within the Session.

我用SignalR更新(一组连接的)大约每新消息。

I've used SignalR to update (a group of connections) about every new message.

现在我明白了,我无法通过集线器访问当前用户的名称。

Now I see that I can't access the name of the current user through the hub.

我想可能会有一些变通方法,但实现我的设计是错的?

I guess there might be some workarounds, but is that implement my design was wrong?

如果我没有用SignalR用于这一目的?或者我不应该以这种方式使用会话

Should I've not used SignalR for that purpose? Or should I not use Session in this way?

推荐答案

您不应该SignalR使用会话(见的会议)。您确定其连​​接ID的逻辑连接,您可以的。

You shouldn't use Session with SignalR (see SignalR doesn't use Session on server). You identify logical connections by their connection id which you can map to user names.

根本的问题是,,以确保国家一致性,所以每个请求到集线器会阻止其他请求。在过去,有限的通过设置EnableSessionstate只读,该prevents我描述)是可能的锁定问题,但对于这个。另请参阅various其他地方的地方SignalR队取得类似的声明。最后:有一个在正式的documentation关于 HTTPContext.Current.Session

The underlying problem is that access to SessionState is serialized in ASP.NET to ensure state consistency, so each request to the hub would block other requests. In the past, limited read-only access (I assume (but can't confirm since the gist is gone) by setting EnableSessionstate to read-only, which prevents the locking problem I described) was possible, but support for this was dropped. Also see various other places where the SignalR team made similar statements. Lastly: there's a statement in the official documentation about HTTPContext.Current.Session.

这篇关于没有获得通过SignalR集线器的会话信息。是我设计的是错的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 02:42