locked
How to keep track of signalr connections related to the current web page information RRS feed

  • Question

  • User979109698 posted

    Anyone know how I can keep track of Signalr reconnections so that I know if a user has stale data that needs to be refreshed? E.g. I have a grid of rows on my web page. I have a timer on my server that will check the database for new records. If a new record is found for a specific connection it will push a signalr notification to the users grid telling them to refresh the grid. Kind of like how facebook has a popup that says 'new info'.  The problem is that if signalr reconnects it can get a new connectionid. The connectionid won't know what the last record the user has in their grid. Is there some way to send client data on a signalr reconnection event to update this related information? When a user manually refreshes their grid or refreshes the page I store the connectionid and the last record timestamp on the server. This design can fail for reconnections tho.

    Wednesday, March 1, 2017 5:56 PM

All replies

  • User-707554951 posted

    Hi jpro1001,

    jpro1001

    Is there some way to send client data on a signalr reconnection event to update this related information?

    Please try to override OnReconnected method in your hub class, and then you could write your code logic to get connectionid of the user and push data and updated client web page.   

    public override Task OnReconnected()
    {       
    //get connectionid of user 
    //and page information that user visited before
    
    //call client function to push data to current connected user
    Clients.Client("connection id").updategrid(data);
    
        return base.OnReconnected();
        
    
    }
    

    jpro1001

    The problem is that if signalr reconnects it can get a new connectionid.

    For user may get a new connectionid issue, we could map SignalR User to Connections, which could help us know who is current user based on his connectionid.

    Best Regards

    cathy

    Thursday, March 2, 2017 8:11 AM