locked
Hub connection timeout RRS feed

  • Question

  • User1251591258 posted

    Hi everybody, I want set the timeout for HubConnection but unknow how to do

    Could you tell me solution?

    Friday, June 7, 2019 3:13 AM

All replies

  • User283571144 posted

    Hi khoicva,

    According to your description, I suggest you could set the connection timeout value  in Application_Start in your Global.asax file.

    More details, you could refer to below codes:

    protected void Application_Start(object sender, EventArgs e)
    {
        // Make long polling connections wait a maximum of 110 seconds for a
        // response. When that time expires, trigger a timeout command and
        // make the client reconnect.
        GlobalHost.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(110);
        
        // Wait a maximum of 30 seconds after a transport connection is lost
        // before raising the Disconnected event to terminate the SignalR connection.
        GlobalHost.Configuration.DisconnectTimeout = TimeSpan.FromSeconds(30);
        
        // For transports other than long polling, send a keepalive packet every
        // 10 seconds. 
        // This value must be no more than 1/3 of the DisconnectTimeout value.
        GlobalHost.Configuration.KeepAlive = TimeSpan.FromSeconds(10);
        
        RouteTable.Routes.MapHubs();
    }

    Article:

    https://docs.microsoft.com/en-us/aspnet/signalr/overview/guide-to-the-api/handling-connection-lifetime-events#timeout-and-keepalive-settings 

    Best Regards,

    Brando

    Friday, June 7, 2019 7:46 AM