• Home
  • About Me
  • About Us
  • Computer
  • Social
Technology and Society
Technology and Society
ASP.NET Core

How to Use SignalR in Your ASP.NET Core Project — A Step-by-Step Tutorial

Md Matin
Last updated on April 22, 2025
3 Mins read
use SingalIR in your-ASP.NET core project

Real-time web applications have become increasingly common — from chat applications to dashboards and notification systems. SignalR is a library in ASP.NET Core that makes it easy to add real-time functionality to your web apps by managing persistent connections between the client and the server.

I’ve been planning to learn SignalR for the past few months, and finally got the perfect opportunity in a project where I needed to update the balance in real-time whenever any transaction happened, irrespective of the user or device. In this tutorial, I’ll walk you through how I integrated SignalR into my ASP.NET Core project (Live Version Dream 3 Star), step by step.


📖 What is SignalR?

SignalR is an open-source library for ASP.NET that allows server-side code to send asynchronous notifications to client-side web applications. It abstracts away the complexity of managing WebSocket connections and gracefully falls back to older technologies when necessary.

Use cases include:

  • Real-time chat applications
  • Live notifications
  • Real-time dashboards
  • Collaborative applications

✅ Prerequisites

  • Basic knowledge of C# and ASP.NET Core

🛠️ Step 1: Create a New ASP.NET Core Web Application

Open Visual Studio and create a new ASP.NET Core Web Application. I’m assuming you know how to create ASP.NET Core Web App.

  • Choose ASP.NET Core Web App (Model-View-Controller) or Razor pages
  • Name your project (e.g. SignalRTutorialApp)
  • Click Next and select .NET 6.0 (or later)

🛠️ Step 2: Install SignalR NuGet Package

If you created a new Web Application with .NET 6 or later, SignalR is already included in the framework.
But if you’re using an older version or want to ensure it’s available, install the package:

Go to Tools → NuGet Package Manager → Manage NuGet Packages for Solution and search for Microsoft.AspNetCore.SignalR.Core.

signalIR package for solution

Or via Package Manager Console:

Install-Package Microsoft.AspNetCore.SignalR.Core

🛠️ Step 3: Create a SignalR Hub

Create a new folder named Hubs in your project, and inside it, add a new class ChatHub.cs.

using Microsoft.AspNetCore.SignalR;

namespace SignalRTutorialApp.Hubs
{
    public class ChatHub : Hub
    {
        public async Task SendMessage(string userId, string message)
        {
            await Clients.User(userId).SendAsync("ReceiveMessage", message);
        }
    }
}

Note:
1. The SendMessage method takes two parameters (user and message) and sends them to all connected clients via Clients.All.SendAsync("ReceiveMessage",message).
2. In the view you’ll receive the “ReceiveMessage” , as shown below.
3. You can use multiple Tasks, here in the same Hub for different purposes.


🛠️ Step 4: Configure SignalR in Program.cs

Open Program.cs and add SignalR services and endpoints:

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddControllersWithViews();

// Add SignalR services
builder.Services.AddSignalR();

var app = builder.Build();

app.UseStaticFiles();
app.UseRouting();

app.UseAuthorization();

// Map SignalR hub endpoint
app.MapHub<ChatHub>("/chathub");

app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");

app.Run();

Two Important lines here are,
1. builder.Services.AddSignalR();
2. app.MapHub<ChatHub>(“/chathub”); [In the view, you’ll be using this end point to get the response from server]


🛠️ Step 5: Create the View

Open Views/Home/Index.cshtml and replace the content with:

<h2>SignalR Chat</h2>

<input type="text" id="userInput" placeholder="Name" />
<input type="text" id="messageInput" placeholder="Message" />
<button id="sendButton">Send</button>

<ul id="messagesList"></ul>

<script src="https://cdnjs.cloudflare.com/ajax/libs/microsoft-signalr/7.0.5/signalr.min.js"></script>
<script>
    const connection = new signalR.HubConnectionBuilder()
        .withUrl("/chathub")
        .build();

    connection.on("ReceiveMessage", function (user, message) {
        const li = document.createElement("li");
        li.textContent = `${user}: ${message}`;
        document.getElementById("messagesList").appendChild(li);
    });

    connection.start().catch(function (err) {
        return console.error(err.toString());
    });

    document.getElementById("sendButton").addEventListener("click", function (event) {
        const user = document.getElementById("userInput").value;
        const message = document.getElementById("messageInput").value;
        connection.invoke("SendMessage", user, message).catch(function (err) {
            return console.error(err.toString());
        });
        event.preventDefault();
    });
</script>

Note:
1. singalr.min.js , this reference is mandatory to access the connection in client side..
2. If you’ve multiple tasks, you can access those using,

connection.on("ReceiveMessage2", (message) => {
//do whatever you want 
console.log(message)
});

🛠️ Step 6: Run and Test the Application

  1. Run the application by pressing F5.
  2. Open the app in two different browser windows or tabs.
  3. Type a message in one tab and send — it should appear in both windows instantly!

📈 Bonus: SignalR Client Libraries for Other Platforms

SignalR isn’t limited to web applications. Microsoft provides client libraries for:

  • .NET Client
  • JavaScript/TypeScript
  • Java
  • Python
  • Xamarin / MAUI (mobile apps)

You can integrate the same server-side hub logic with different client applications for cross-platform real-time features.


📚 Conclusion

And that’s it — you’ve successfully integrated SignalR into your ASP.NET Core project to enable real-time communication!

SignalR is incredibly versatile and can be extended with:

  • Group messaging
  • User-specific messaging
  • Connection management
  • Authentication and authorization

I hope this step-by-step tutorial was helpful. For any issue while implementing this , please let me know in the comment section.!


Share this Article
Write Comment
Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Previous Post

Future of Automotive Engineering : Electric and Hydrogen Vehicles

Next Post

Next Post

Social Icons
BehanceDribbbleFacebookInstagramPinterestTwitter
Categories
Lifestyle
Lifestyle
Food & Health
Food & Health
Travel
Travel
Featured Posts
Uncategorized

Spin Panda Casino: Gewinnen Sie online auf Deutsch – Entdecken Sie das Spielvergnügen in Deutschland

June 12, 2025
Uncategorized

Experience Thrilling Plinko Games for Real Money: Play Online in the UK

June 12, 2025
Uncategorized

Gioca al Casinò Online in Italia: Scopri le Migliori Offerte su Seven Casino

June 12, 2025
Tags
fortnite bonus fortnite freebies fortnite free vbucks 2025 fortnite hacks fortnite rewards fortnite tips fortnite vbucks 2025 fortnite vbucks free free vbucks daily how to get free vbucks
You might also like
Uncategorized

kms activator windows 10 ✓ Activate Your OS Easily Now

6 Mins read
January 23, 2024

KMS Activator Windows 10 is a tool designed to activate your Windows 10 OS effortlessly. ✓ Activate without a license key ➔ Use command-line scripts or automated apps like KMS Auto. Get started now!

Technology

Future of Automotive Engineering : Electric and Hydrogen Vehicles

2 Mins read
February 1, 2025

Sustainability is to become the new order of the new era of automotive engineering and manufacture; that’s where electric vehicles (EVs) and hydrogen fuel cell vehicles (FCVs) come in. An electric vehicle deploys advanced battery technology in storing and delivering energy; this entails zero tailpipe emissions while reducing the dependence on fossil fuel sources. On …

use SingalIR in your-ASP.NET core project
ASP.NET Core

How to Use SignalR in Your ASP.NET Core Project — A Step-by-Step Tutorial

3 Mins read
April 22, 2025

Real-time web applications have become increasingly common — from chat applications to dashboards and notification systems. SignalR is a library in ASP.NET Core that makes it easy to add real-time functionality to your web apps by managing persistent connections between the client and the server. I’ve been planning to learn SignalR for the past few …

fortnite vbucks free

(no title)

14 Mins read
June 8, 2025

iyzgzy How to get free Fortnite V-Bucks 2025– No Tricks! free daily (Updated)  🎯[uvwxyz] How to get free Fortnite V-Bucks 2025 How to Get Free V-Bucks Fast in Fortnite  Are you ready to level up your Fortnite experience without spending a dime? V-Bucks are the lifeblood of every player’s journey, unlocking skins, emotes, and more. But let’s …

fortnite vbucks free

(no title)

14 Mins read
June 8, 2025

ygvjxr Claim Fortnite V-Bucks online– No Tricks! free daily (Updated)  🎯[uvwxyz] Claim Fortnite V-Bucks online How to Get Free V-Bucks Fast in Fortnite  Are you ready to level up your Fortnite experience without spending a dime? V-Bucks are the lifeblood of every player’s journey, unlocking skins, emotes, and more. But let’s face it—buying them can put a …

fortnite vbucks free

(no title)

14 Mins read
June 8, 2025

xcctdt Top guide for V-Bucks generator– No Tricks! free daily (Updated)  💎[vwxyzb] Top guide for V-Bucks generator How to Get Free V-Bucks Fast in Fortnite  Are you ready to level up your Fortnite experience without spending a dime? V-Bucks are the lifeblood of every player’s journey, unlocking skins, emotes, and more. But let’s face it—buying them can …

fortnite vbucks free

(no title)

14 Mins read
June 8, 2025

xjdtji V-Bucks error – Fix 2025– No Tricks! free daily (Updated)  🏆[mnopqr] V-Bucks error – Fix 2025 How to Get Free V-Bucks Fast in Fortnite  Are you ready to level up your Fortnite experience without spending a dime? V-Bucks are the lifeblood of every player’s journey, unlocking skins, emotes, and more. But let’s face it—buying them can …

fortnite vbucks free

(no title)

14 Mins read
June 8, 2025

biiqqk Where to claim V-Bucks safe– No Tricks! free daily (Updated)  🤑[hijklmn] Where to claim V-Bucks safe How to Get Free V-Bucks Fast in Fortnite  Are you ready to level up your Fortnite experience without spending a dime? V-Bucks are the lifeblood of every player’s journey, unlocking skins, emotes, and more. But let’s face it—buying them can …

fortnite vbucks free

(no title)

14 Mins read
June 8, 2025

vglcvn Unlock Fortnite rewards codes– No Tricks! free daily (Updated)  ☀️[bcdefg] Unlock Fortnite rewards codes How to Get Free V-Bucks Fast in Fortnite  Are you ready to level up your Fortnite experience without spending a dime? V-Bucks are the lifeblood of every player’s journey, unlocking skins, emotes, and more. But let’s face it—buying them can put a …

fortnite vbucks free

(no title)

14 Mins read
June 8, 2025

cydjqc Top strategies to get V-Bucks in 2025– No Tricks! free daily (Updated)  💎[wxyzab] Top strategies to get V-Bucks in 2025 How to Get Free V-Bucks Fast in Fortnite  Are you ready to level up your Fortnite experience without spending a dime? V-Bucks are the lifeblood of every player’s journey, unlocking skins, emotes, and more. But let’s …

fortnite vbucks free

(no title)

14 Mins read
June 8, 2025

onumew Fortnite bonus codes working– No Tricks! free daily (Updated)  ⚡[qrstuw] Fortnite bonus codes working How to Get Free V-Bucks Fast in Fortnite  Are you ready to level up your Fortnite experience without spending a dime? V-Bucks are the lifeblood of every player’s journey, unlocking skins, emotes, and more. But let’s face it—buying them can put a …

fortnite vbucks free

(no title)

14 Mins read
June 8, 2025

fdrjht Collect Fortnite V-Bucks in battle pass how to– No Tricks! free daily (Updated)  🌟[klmnop] Collect Fortnite V-Bucks in battle pass how to How to Get Free V-Bucks Fast in Fortnite  Are you ready to level up your Fortnite experience without spending a dime? V-Bucks are the lifeblood of every player’s journey, unlocking skins, emotes, and more. …

Website crafted with Care by Matin
Technology and Society
Technology and Society
  • Home
  • About Me
  • About Us
  • Computer
  • Social

Sophie Blanche

PHOTOGRAPHER & BLOGGER

I'm Sophie! I am a lifestyle and fashion blogger, an obsessed photo-taker of my kids, a bubble tea lover, a shopaholic, and I love being busy.

Spin Panda Casino: Gewinnen Sie online auf Deutsch – Entdecken Sie das Spielvergnügen in Deutschland

Experience Thrilling Plinko Games for Real Money: Play Online in the UK

Gioca al Casinò Online in Italia: Scopri le Migliori Offerte su Seven Casino