SignalR loses connection when giving a PostBack

2

The idea is to keep the user logged in to Chat as he browses the pages.

Layout of components on the page

  • Layout.cshtml

    function iniciarChat() {
    
        var chatHub = $.connection.chat;
        $.connection.hub.start();
    
    }
    
  • Index.cshtml

    iniciarChat();
    

Today the structure is like this. But when the user clicks on a link that does a PostBack, it is disconnected from Chat . And when it returns to Index.cshtml, it reconnects to Chat again.

I would like to know if you have any way to keep the user logged in to Chat even though he does a PostBack.

    
asked by anonymous 25.06.2015 / 15:21

1 answer

1

What is the structure of your Hub ?

I believe you will need to make a control on OnDisconnected and when adding the user to a new session.

When it "unplug" you will have to keep it still in the mapping sessions for X time hoping it will come back, when it moves to the next page you just check if the user had already created the session and assign it to it again .

The biggest problem will be in this "management" in time to expire, but how much to disconnect everything depends on your code in .OnDisconnected .

On "PostBack" it only exists when the user sends, for example, a submit pro server and it continues on the page. When you browse between pages no it is a PostBack . So it's not that way;)

    
25.06.2015 / 15:45