asp.net - Reusing same connection in signalR while navigating through different pages -
i have mvc project, multiple pages.
i have long running process, updates client on progress. however, update sent single client, instead of broadcasting all.
clients.client(connectionid).sendmessage(msg);
in layout.cshtml, how connect hub
var serverhub = $.connection.notifier; window.hubready = $.connection.hub.start(function () { });
the problem is, when navigate page, no longer receive messages signalr, because connection id has changed.
how should workaround issue, such signalr hub can still send messages single client, while client navigates page page.
you want create server mapping of users connection id's. see: signalr 1.0 beta connection factory.
you want let users persist past ondisconnected event , when connect different connection id can continue pumping data down them.
so thought process follows:
- page loads, signalr connection instantiated
- once connection started call => trycreateuser (returns user, whether existed or created).
- long running process starts
- client changes pages -> signalr connection stops
- new page loads, new signalr connection instantiated
- once connection started see if have cookie, session, or type of data representing => trycreateuser(userdata) (returns user created on last page).
- data continues pumping down user.
note: if take authentication approach have authenticated prior starting connection , data cannot change during lifetime of signalr connection, can created/modified while connection in disconnected state.
Comments
Post a Comment