Before we can use our SignalR real-time API, we need to enable SignalR and define the path for the endpoint. Let's carry out the following steps in Startup.cs:
- We'll start by referencing our SignalR hub with the following using statement:
using QandA.Hubs;
- Add SignalR to our ASP.NET app by using the AddSignalR method in the services parameter in the ConfigureServices method:
public void ConfigureServices(IServiceCollection services)
{
...
services.AddSignalR();
}
- The next step is to configure the request pipeline so that we can pass SignalR requests to our SignalR hub:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
...
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapHub<QuestionsHub>("/questionshub");
});
}
So, SignalR requests to the /questionshub...