locked
Refresh browser and lose connection. RRS feed

  • Question

  • User8510899 posted
    Hi friends, in this discussion (https://forums.asp.net/t/2135160.aspx?Signalr+send+message+to+group) I have write complete code of my project. When I refresh browser the connection is always lost and need to reclick button for reload new connection. There is a solution for this? Can you show me what the best approach to the problem? Thanks to all.
    Best Regards.
    Wednesday, January 24, 2018 9:38 PM

All replies

  • User61956409 posted

    Hi Best79,

    When I refresh browser the connection is always lost and need to reclick button for reload new connection.

    When the user refreshes the page (or closes a browser window or tab, or navigates to a new page), the SignalR connection immediately ends because SignalR client code handles that browser event for you and calls the Stop method.

    For more information about connection lifetime events in SignalR, please refer to this article.

    With Regards,

    Fei Han

    Thursday, January 25, 2018 5:30 AM
  • User8510899 posted

    Hi Fei Han, in my server code i need to implement also a function "OnReconnected" like this?:

    Public Overrides Function OnReconnected() As Task
        Connections.TryAdd(Context.ConnectionId, Nothing)
        Return MyBase.OnReconnected()
    End Function

    My problem is the refresh page and user "off-on" continuously...

    I'm confused.

    Friday, January 26, 2018 6:36 PM
  • User61956409 posted

    Hi Best79,

    As I mentioned in previous reply, the SignalR connection immediately ends if user refreshes the page. If you want user automatically start a connection after refresh web page, you can try to explicitly call start method $.connection.hub.start() in jQuery document ready event.

    With Regards,

    Fei Han

    Tuesday, January 30, 2018 8:24 AM