问题
Why SignalR is making different connection in browser multiple tabs for same logged-in user. Is there any way to make one connection for all tabs opened in same browser. From connection I mean connectionID of a user in SignalR.
回答1:
Because different tabs of the same browser are different documents\"processes" - each tab in some sense represents different "instance" of client app. There is no way to share JavaScript objects between them directly (and thats the reason why SignalR opens new connection in each tab). To share data\communicate between different instances, you can use for example HTML5 localStorage mechanism
So if you want to share one SignalR connection between tabs, the way to go is to implement it yourself by managing connection only in one tab and allowing communication between tabs so that every tab has the ability to send\receive messages from server. You can use or get inspired by this cool project which does exactly that.
This also solves the problem of browser limit of maximum concurrent connections to single server.
来源:https://stackoverflow.com/questions/30587888/different-connection-in-browser-multiple-tabs