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,800 courses taught by industry experts.

Solution: Create a SignalR application

Solution: Create a SignalR application

(upbeat music) - [Instructor] I'll now show you how I solved the challenge. I could add the signal R functionality to an existing application, but for the sake of simplicity, I'll create a new Razor pages app. I'll do that in my terminal with the command dotnet new webapp. I'll put it in a folder named signalr-challenge. With that created, I'll go into the new folder and open the project in VS code. I'm first going to implement the server code. I'll do that with a new hub class in a file named SalesHub.cs. I first want to pull in the Microsoft.AspNetCore.SignalR namespace. I'll now declare the new SalesHub class and have it inherit from the base Hub class. For the basic functionality in the challenge, I only need to add a single method to the class named PostNewSale. It is an async method that takes a new sales amount as an integer parameter. I only want the server to alert the client of new sales if the sale is greater than $1,000. I'm using the SendAsync method to call…

Contents