Can I use SignalR with ASP.NET Core? Yes, you can.

Posted: (EET/GMT+2)

 

If you have used SignalR in classic ASP.NET applications, you'll be happy to know that SignalR is fully available in ASP.NET Core as well. In fact, the new version is rewritten for .NET Core and is lighter, faster, and easier to deploy.

To get started, add the SignalR package (example of CLI installation, but you can naturally do this in Visual Studio, too):

dotnet add package Microsoft.AspNetCore.SignalR

Then configure SignalR in your Startup class:

public void ConfigureServices(IServiceCollection services)
{
    services.AddSignalR();
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    app.UseStaticFiles();
    app.UseRouting();

    app.UseEndpoints(endpoints =>
    {
        endpoints.MapHub<ChatHub>("/chat");
    });
}

And finally, create a hub:

public class ChatHub : Hub
{
    public Task SendMessage(string user, string message)
    {
        return Clients.All.SendAsync("ReceiveMessage", user, message);
    }
}

What I really like about the ASP.NET Core version is that it supports WebSockets, Server-Sent Events, and long polling, selecting the best transport available automatically. The JavaScript client API has also been simplified.

If your application needs real-time updates—dashboards, notifications, chat, monitoring—SignalR in ASP.NET Core is a very natural fit.

Happy hacking!