Reusing same connection in signalR while navigating through different pages

前端 未结 1 711
被撕碎了的回忆
被撕碎了的回忆 2021-01-02 12:49

I have an MVC project, with multiple pages.

I have a long running process, which updates the client on its progress. However, this update is sent only to a single c

相关标签:
1条回答
  • 2021-01-02 13:21

    You will want to create a server mapping of users to connection id's. See: SignalR 1.0 beta connection factory.

    You will want to let your users persist past an OnDisconnected event and when they connect with a different connection Id you can continue pumping data down to them.

    So the thought process could be as follows:

    1. Page loads, SignalR connection is instantiated
    2. Once connection is fully started call => TryCreateUser (returns a user, whether it existed or it was created).
    3. Long Running process Starts
    4. Client changes pages -> SignalR connection stops
    5. New Page loads, new SignalR connection is instantiated
    6. Once connection is fully started see if you have a cookie, session, or some type of data representing who you are => TryCreateUser(userData) (returns the user you created on the last page).
    7. Data continues pumping down to user.

    Note: if you take an authentication approach you will have to be authenticated prior to starting a connection and that data cannot change during the lifetime of a SignalR connection, it can only be created/modified while the connection is in the disconnected state.

    0 讨论(0)
提交回复
热议问题