blazor Server timeout while debugging

Viewed 1446

If I debug my code for more than 30 seconds, the web page shows

"Attempting to reconnect to the server: # of 8"

and dev console message is

"Error: Connection disconnected with error 'Error: Server timeout elapsed without receiving a message from the server".

Is there any setting that can disable timeout or at least make it way longer than it is now?

3 Answers

In case you use long polling you need to add also this configuration option:

app.UseEndpoints(endpoints =>
    // other settings go here
    endpoints.MapBlazorHub(options => {
        options.WebSockets.CloseTimeout = new TimeSpan(1, 1, 1);
        options.LongPolling.PollTimeout = new TimeSpan(1, 0, 0);
    })
);

Try adding this in your Startup.cs or Program.cs, whichever one you're using and set then TimeSpan to your desired timeout length:

app.UseEndpoints(endpoints =>
    // other settings go here
    endpoints.MapBlazorHub(options => options.WebSockets.CloseTimeout = new TimeSpan(1, 1, 1));
});

Modify the _Layout.cshtml:

<environment include="Development">
  <script src="_framework/blazor.server.js" autostart="false"></script>
  <script>
    Blazor.start({
      configureSignalR: function (builder)
      {
        let c = builder.build();
        c.serverTimeoutInMilliseconds = 9999999;
        builder.build = () => c;
      }});
  </script>
</environment>
<environment exclude="Development">
  <script src="_framework/blazor.server.js"></script>
</environment>
Related