Member-only story
Real-Time Progress Bar Update with SignalR in ASP.NET Core
2 min readFeb 6, 2025
While processing Excel rows, send real-time progress updates to the client.
The progress bar will update based on messages received from the server.
Install SignalR
In Visual Studio, install the following packages via NuGet Package Manager:
Microsoft.AspNetCore.SignalR
Microsoft.AspNetCore.SignalR.Client
Define the SignalR Hub
Create a Hubs folder and add a ProgressHub.cs file:
using Microsoft.AspNetCore.SignalR;
using System.Threading.Tasks;
public class ProgressHub : Hub
{
public async Task SendProgress(int progress)
{
await Clients.All.SendAsync("ReceiveProgress", progress);
}
}
Configure SignalR in ASP.NET Core
Add SignalR support in Program.cs:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllersWithViews();
builder.Services.AddSignalR(); // Add SignalR service
var app = builder.Build();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapHub<ProgressHub>("/progressHub"); // Register SignalR Hub
});
app.Run();
Update Excel Import Method with Progress Updates
Modify the importExcel method in the controller:
[HttpPost]
public…