Invoking a hub method from an HTTP controller – announcing user login
In this recipe, we will explore how to invoke hub methods not from a SignalR client but from HTTP Web API controller endpoints on our server. This technique is particularly useful for adding contextual information (such as locale) without cluttering the hub methods.
We will modify our HTTP POST login endpoint to announce to all connected SignalR clients when a new client has logged in.
Getting ready
You can clone the starter project here: https://github.com/PacktPublishing/ASP.NET-9-Web-API-Cookbook/tree/main/start/chapter06/HubInController or continue from the preceding recipe.
SignalR is always tightly coupled with a client. In the project folder, there is both a console client you can use in the terminal and a web page in the server project that is set up to work with this example. Use either or both to test this recipe.
How to do it…
- The first thing we have to do is upgrade...