SignalR doesn't use Session on server

2019-01-09 05:33发布

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?

3条回答
我命由我不由天
2楼-- · 2019-01-09 05:40

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.

查看更多
Deceive 欺骗
3楼-- · 2019-01-09 05:56

I resolve the same problem with hidden field as follows:

  1. Added ASP Hiddenfield on the aspx page.
  2. assigned the session value on page load (in my case on button client event)
  3. sent the value to the SignalR Hub using $("FieldID").val()
查看更多
该账号已被封号
4楼-- · 2019-01-09 06:01

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.

查看更多
登录 后发表回答