locked
OnDisconnect not being called on tab close RRS feed

  • Question

  • User-1067808729 posted

    AspNet.SignalR 2.4.1
    AspNet.SignalR.Core 2.4.1

    Issue Occurring in:
    Chrome Version 88.0.4324.182 (Official Build) (64-bit)
    Firefox 84.0.2 (64-bit)

    Workflow:
    I log in to my web-application, on the main screen I connect to my hub, get my connection Id and all
    the usual things; I leave the tab running.
    If I then log into my application again as a different user (new tab or window) it creates a new 
    sessionId and new connectionId as expected.

    The problem arises when I close the tab for the 1st instance of my application, the ondisconnect is 
    not called. This issue doesn't occur if I close a tab associated with the latest instance of my 
    application.

    If I manually call OnDisconnect on the server side for the first instance of the application, 
    context is null. If I manually call OnDisconnect on the client side, it doesn't get called on the 
    server-side. Again, only for the first instance of my web-application 

    Adding either one of the following on window.onbeforeunload didn't help:
    $.connection.hubName.connection.stop();
    $.connection.hub.stop();

    Tuesday, February 23, 2021 7:13 PM

Answers

  • User-1067808729 posted

    Apparently what I'm trying to do in my application is not allowed by SignalR by design.

    https://github.com/SignalR/SignalR/issues/4529#issuecomment-786298886

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 26, 2021 12:45 AM

All replies

  • User-939850651 posted

    Hi TonyBeCoding,

    The problem arises when I close the tab for the 1st instance of my application, the ondisconnect is 
    not called. This issue doesn't occur if I close a tab associated with the latest instance of my 
    application.

    How did you test it?

    If you need it to be able to run in multiple tabs at the same time, You need to copy the URL from the address bar, open another browser instance or tab, and paste the URL in the address bar.

    For more details, please refer to related document:

    Get started with ASP.NET Core SignalR - Run the app

    Best regards,

    Xudong Peng

    Wednesday, February 24, 2021 2:57 AM
  • User-1067808729 posted

    This is not a viable solution for me. I figured since all tabs have their own connectionId and the usual signalR stuff setup, that whenever I close one tab it would trigger the ondisconnect.

    Wednesday, February 24, 2021 3:12 PM
  • User475983607 posted

    Session uses cookies to store the Session Id.  Cookies are bound to the browser instance not the tab.   Your design loses the first Session.  

    Try opening another browser instance rather than a tab.

    Wednesday, February 24, 2021 3:32 PM
  • User-1067808729 posted

    Apparently what I'm trying to do in my application is not allowed by SignalR by design.

    https://github.com/SignalR/SignalR/issues/4529#issuecomment-786298886

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 26, 2021 12:45 AM