From the course: Learning ASP.NET Core: MVC, Razor Pages, Web APIs & Other Foundations
Unlock this course with a free trial
Join today to access over 24,600 courses taught by industry experts.
Creating a server hub
From the course: Learning ASP.NET Core: MVC, Razor Pages, Web APIs & Other Foundations
Creating a server hub
- [Instructor] Because you can really add SignalR functionality to any ASP.NET Core application, I'm not going to create a new application for this demo. Instead, I'll just add a new feature to an app I created earlier in the course. I'm going to add the ability to post messages inside the app. When new messages are received by the server, it will notify all clients and update them with the new message. I've already opened the razor-pages app I created while demonstrating it a few chapters back. In this movie, I'm going to focus on adding the server-side SignalR code, and in the next movie, we'll add the slightly more complex client-side code. The main thing I need to add to the server is a new hub class. I'll add a new file to the root of the project named MessageHub.cs. ASP.NET Core includes a hub base class in the Microsoft.AspNetCore.SignalR namespace. (keyboard clacking) I'll now just declare a new class named MessageHub that inherits from the built-in Hub base class. (keyboard…