How do you set up a basic SignalR Hub in an ASP.NET Core application?
113
21-May-2025
Utpal Vishwas
21-May-20251. Create a new ASP.NET Core project
You can start with an empty Web API or Web app project.
2. Add the SignalR package
If you don’t already have it, add the SignalR NuGet package:
3. Create a SignalR Hub class
A Hub is a central class where clients and server communicate.
Create a new class like this:
4. Configure SignalR in Startup (
Program.cs
for .NET 6+)In ASP.NET Core 6 or later,
Program.cs
will look something like this:For ASP.NET Core 3.1 or 5, you add SignalR in
Startup.cs
:5. Client-side setup
You can use JavaScript to connect to the SignalR hub. Include the SignalR client library (from CDN or npm):
Summary
Microsoft.AspNetCore.SignalR
Program.cs
orStartup.cs
add SignalR and map hub route