In this article, we will learn how to use SignalR Core in ASP.NET Core 2.0 web applications to provide real-time communication.
Scenario
After processing a payroll, the system will trigger a report generation process. Once this process is complete, we want to notify all the web clients that their reports are available to view.
Note
I want to demonstrate a real world usage of SignalR but also want to keep it simple enough. Like SignalR, this post is ‘alpha’ too, i.e., be gentle in your feedback if you find bugs
Note - I am assuming that you are familiar with the previous version of SignalR. If not, please check the documentation here.
Solution
We will build two applications: Server and Client. The server will receive notifications from the reporting engine when reports are ready and in-turn, it will notify the clients.
Server
Create an empty console application (.NET Core) and add NuGet packages.
- AspNetCore.All
- AspNetCore.SignalR
Update the Program class.
- public class Program
- {
- public static void Main(string[] args)
- {
- BuildWebHost(args).Run();
- }
- public static IWebHost BuildWebHost(string[] args) =>
- WebHost.CreateDefaultBuilder(args)
- .UseStartup<Startup>()
- .Build();
- }
Add a Startup class to add services and middleware for SignalR.
- public class Startup
- {
- public void ConfigureServices(
- IServiceCollection services)
- {
- services.AddCors(options =>
- {
- options.AddPolicy("fiver",
- policy => policy.AllowAnyOrigin()
- .AllowAnyHeader()
- .AllowAnyMethod());
- });
- services.AddSignalR(); // <-- SignalR
- }
- public void Configure(
- IApplicationBuilder app,
- IHostingEnvironment env)
- {
- app.UseCors("fiver");
- app.UseSignalR(routes => // <-- SignalR
- {
- routes.MapHub<ReportsPublisher>("reportsPublisher");
- });
- }
- }
Create a class that inherits from SignalR Hub class.
- public class ReportsPublisher : Hub
- {
- public Task PublishReport(string reportName)
- {
- return Clients.All.InvokeAsync("OnReportPublished", reportName);
- }
- }
Client
Create an empty ASP.NET Core 2.0 web application and add NuGet package Microsoft.AspNetCore.SignalR. Update the Startup class to add services and middleware for MVC.

Knox NorthPosted Sep 30, 2017, 4:29 PM
I don't find a nu-get package for AspNetCore.SignalR
Sajid HussainPosted Sep 11, 2017, 12:36 AM
Nice effort,Keep it up.