Hi, in Blazor Server, the error "Attempting to connect to the server..." means the SignalR connection was lost between the client and server.
Here’s a clear checklist to fix or reduce this issue:
- Enable WebSockets (required for SignalR)
On IIS or Azure App Service:
- IIS: Install the WebSocket Protocol feature via Server Manager.
- Azure App Service: In the Azure Portal, go to your App Service → Configuration → General Settings → Enable Web sockets.
If behind a reverse proxy (e.g., Nginx or Apache): You must forward WebSocket headers:
For Nginx:
location /_blazor {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
- Prevent Idle Timeout (especially on Azure)
Azure App Service will unload your app after idle time by default.
Fix:
- In the Azure Portal, go to your App Service → Configuration → turn on Always On.
- Handle Reconnect Attempts (in Blazor Server)
You can make Blazor attempt automatic reconnection. Create a JavaScript snippet to override the default SignalR behavior:
Add to _Host.cshtml
(before </body>
):
<script src="_framework/blazor.server.js" autostart="false"></script>
<script>
Blazor.start({
reconnectionOptions: {
maxRetries: 10,
retryInterval: 3000
}
});
</script>
- Increase KeepAliveInterval and Timeout Settings
In Program.cs
:
builder.Services.AddServerSideBlazor()
.AddHubOptions(options =>
{
options.ClientTimeoutInterval = TimeSpan.FromSeconds(60);
options.KeepAliveInterval = TimeSpan.FromSeconds(15);
});
- Avoid Blocking Calls
Don’t use Thread.Sleep
or heavy synchronous work in components — it can block SignalR pings.
Use async
/await
and background services for long tasks.
- Inspect Logs for Disconnects
Enable detailed logging to see disconnection causes:
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore.SignalR": "Debug",
"Microsoft.AspNetCore.Http.Connections": "Debug"
}
}
- Network Stability on Client Side
Sometimes the issue is the user’s browser or Wi-Fi dropping packets.
You can handle this more gracefully by showing a custom UI when disconnected (Blazor provides OnConnectionUp
, OnConnectionDown
events with JavaScript interop).
Hope this helps.