How to Build Real-Time Web Apps Using SignalR in ASP.NET Core

23 Sep 2025
The modern digitalized society requires the user to be able to get instant communication with the world, whether that is having a chat with your friends, getting real-time updates on stock prices, or live notifications. To developers, the expectations entail the creation of apps that are alive, connected, and immediate.
That’s where ASP.NET Core SignalR comes in.
SignalR gives developers the opportunity to create real-time web applications that provide real-time updates between clients and servers. SignalR makes the process of building a chat app, whiteboard system, dashboard, or live notifications system simple in ASP.NET Core.
The current step-by-step SignalR tutorial with ASP.NET Core will learn everything you want to know about the setup to production best practices so that you can safely begin to create apps in ASP.NET Core that are real-time.
What is SignalR and Why Use It?
SignalR, fundamentally, is a real-time communication library of ASP.NET Core. It enables servers to push content to clients who are connected in real-time, and not have clients request updates over and over again.
How SignalR Works
- WebSockets First: SignalR will use WebSockets where possible, and this is the fastest and most efficient connection.
- Fallback Mechanism: In case WebSockets are not available, it will be replaced by alternative ways of connecting, such as Server-Sent Events (SSE) or Long Polling, and thus, reliable connections will be ensured among devices and browsers.
Benefits for Developers
- Make real-time chat apps with ease.
- Create dashboards without the need for page refreshes.
- Offer social media, trading, or live sports.
- Introduce real-time notifications of SaaS.
In other words, SignalR enables real-time web applications to operate without necessarily having to begin from scratch.
Setting Up an ASP.NET Core Project with SignalR
Create your ASP.NET Core SignalR project before you begin real-time coding.
Step 1: Create a New ASP.NET Core Project
In the first step, you need to start your Visual Studio or terminal for a new project:
Dotnet new webapp -n RealTimeApp
Step 2: Add the SignalR NuGet Package
Install the SignalR server library:
Dotnet add package Microsoft.AspNetCore.SignalR
Step 3: Configure SignalR in Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();
services.AddSignalR();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseRouting();
app.UseEndpoints(endpoints =
{
endpoints.MapRazorPages();
endpoints.MapHub
});
}
Creating a SignalR Hub
Example: Real-Time Chat Hub
using Microsoft.AspNetCore.SignalR;
public class ChatHub: Hub
{
public async Task SendMessage(string user, string message)
{
await Clients.All.SendAsync("ReceiveMessage", user, message);
}
}
Building the Client-Side Connection
npm install @microsoft/signalr
const connection = new signalR.HubConnectionBuilder()
.withUrl("/chatHub")
.build();
connection.on("ReceiveMessage", (user, message) => {
const msg = `${user}: ${message}`;
console.log(msg);
});
connection.start().catch(err => console.error(err.toString()));
Adding Real-Time Features (Examples)
Users can send and receive messages instantly.
Ideal for customer service or social sites.
Push notifications for the placement of a new order.
Display the health of the show systems on the admin dashboards.
Update users with the latest market data.
Great for fintech, trading, or analytics apps.
Testing and Debugging SignalR
Connection errors: Check hub routes and CORS policies. Messages not received: Make sure that clients have been subscribed properly. Scaling problems: Azure SignalR Service load handling.
Best Practices for SignalR in Production
Scale with the Azure SignalR Service: Scale due to thousands of clients. Apply Authentication: JWTs or cookies are to be used as security measures for the hubs. Improve Performance: Reduce load sizes and utilize groups to have the greatest impact. Monitor Connections: Track down disconnections and reconnections in order to detect connections.