SlideShare a Scribd company logo
Fancy Features in
Asp.Net Core SignalR
Vladimir Georgiev
Software Development Lead @ Concep
VGeorgiev.org
Fancy Features in Asp.Net Core SignalR
Fancy Features in Asp.Net Core SignalR
Fancy Features in Asp.Net Core SignalR
Real time web apps are not fancy anymore
Users expect Real-Time
HTTP
HTTP
Long Polling & Server-Sent Events
…
connection
close connection
events
Web Sockets
open connection
close connection
SignalR
Fancy Features in Asp.Net Core SignalR
SignalR Configuration
app.UseSignalR(routes =>
{
routes.MapHub<ChatHub>("/chatHub");
});
services.AddSignalR()
Startup.cs
https://docs.microsoft.com/en-us/aspnet/core/tutorials/signalr
• Use Visual Studio 2017 15.8+
• Use .NET Core SDK 2.1+
SignalR Hub
public class ChatHub : Hub
{
public async Task SendMessage(string user, string message)
{
await Clients.All.SendAsync("receiveMessage", user, message);
}
}
ChatHub.cs
Client-side Code
var connection = new signalR.HubConnectionBuilder()
.withUrl("/chatHub").build();
connection.on("receiveMessage", function (user, message) {
// Append the message to DOM
});
connection.start();
document.getElementById("sendButton").addEventListener("click",
function (event) {
connection.invoke("SendMessage", user, message);
});
chat.js
JSON & MessagePack
Protocols
JSON & MessagePack Protocols
Install package Microsoft.AspNetCore.SignalR.Protocols.MessagePack
services.AddSignalR().AddMessagePackProtocol();
var connection = new signalR.HubConnectionBuilder()
.withHubProtocol(new signalR.protocols.msgpack.MessagePackHubProtocol())
.withUrl("/chatHub").build();
<script src="~/lib/signalr/signalr.js"></script>
<script src="~/lib/msgpack5/msgpack5.js"></script>
<script src="~/lib/signalr/signalr-protocol-msgpack.js"></script>
Inject IHubContext
Injecting HubContext everywhere
public class ChatController : ControllerBase
{
private readonly IHubContext<ChatHub> chatHub;
public ChatController(IHubContext<ChatHub> chatHub)
{
this.chatHub = chatHub;
}
[HttpGet("/Message")]
public Task SendMessage(string message)
{
return this.chatHub.Clients.All.SendAsync("receiveMessage",
"Controller", message);
}
}
Strongly-Typed Hubs
Dynamic & magic string calls
• ASP.NET SignalR
• Asp.Net Core SignalR
Clients.All.broadcastMessage(name, message);
Clients.All.SendAsync("receiveMessage", user, message);
Strongly Typed Hubs
public class StronglyTypedHub : Hub<IChatClient>
{
public async Task SendMessage(string user, string message)
{
await Clients.All.ReceiveMessage(user, message);
}
}
public interface IChatClient
{
Task ReceiveMessage(string user, string message);
}
Authentication & Authorization
Authentication & Authorization
• Cookie authentication
• Bearer token authentication
[Authorize]
public class ChatHub : Hub
{
[Authorize("MyAuthorizationPolicy")]
public async Task Send(string message)
{
}
}
Streaming
Streaming
public ChannelReader<string> ShowMeTheWords(int delay)
StreamingHub.cs
Streaming
public ChannelReader<string> ShowMeTheWords(int delay)
var channel = Channel.CreateUnbounded<string>();
return channel.Reader;
StreamingHub.cs
Streaming
public ChannelReader<string> ShowMeTheWords(int delay)
var channel = Channel.CreateUnbounded<string>();
return channel.Reader;
await writer.WriteAsync(words[i]);
writer.Complete();
StreamingHub.cs
Streaming
private List<string> words = { /* some words */ };
public ChannelReader<string> ShowMeTheWords(int delay)
{
var channel = Channel.CreateUnbounded<string>();
_ = WriteItemsAsync(channel.Writer, delay);
return channel.Reader;
}
private async Task WriteItemsAsync(ChannelWriter<string> w, int delay)
{
for (var i = 0; i < words.Count; i++)
{
await writer.WriteAsync(words[i]);
await Task.Delay(delay);
}
writer.Complete();
}
StreamingHub.cs
Streaming
var connection = new signalR.HubConnectionBuilder()
.withUrl("/streamingHub").build();
connection.start();
connection.stream("ShowMeTheWords", 750).subscribe({
next: (item) => { /* render item */ },
complete: () => { /* complete */ },
error: (err) => { /* show error */ }
});
Streaming.js
Summary
• SignalR
• MessagePack
• HubContext
• Strongly-Typed Hubs
• Authentication & Authorization
• Streaming
Fancy Features in Asp.Net Core SignalR
Use Real-Time
Vladimir Georgiev
VGeorgiev.org

More Related Content

What's hot (19)

PDF
Debug production server by counter
Roy Chung-Cheng Lou
 
PPTX
Serverless Computing With Azure Functions
Jaliya Udagedara
 
PDF
Kube 1.2
Diógenes Rettori
 
PDF
DevNation Workshop: Object detection with Red Hat OpenShift Data Science [Mar...
Red Hat Developers
 
PPT
The IMPACT Interoperability Framework - Workflows for OCR and beyond
cneudecker
 
PPTX
API Versioning in the Cloud
Cloud Elements
 
PDF
[Kotlin Serverless 工作坊] 單元 2 - 簡介 Kotlin Serverless
Shengyou Fan
 
PPTX
Going Serverless with Iron.io
Isak Rickyanto
 
PPTX
Asp.net mvc 4
Milestone Internet Marketing
 
PPTX
Azure Durable Functions
Karthikeyan VK
 
PPTX
Bluetooth low energy
Alex Hihi
 
PPTX
A lap around azure function proxy
Wagner Silveira
 
PDF
HAProxyConf 2019: Building a Service Mesh at Criteo with Consul and HAProxy
Pierre Souchay
 
PPTX
Building Apps with MySpace SDKs
MySpaceDevTeam
 
PPTX
2019 05-28 SRE Consul Criteo Meetup
Pierre Souchay
 
PDF
Microservices:
 The phantom menace
. Istio Service Mesh: 
the new hope
Sergii Bishyr
 
PDF
PuppetConf 2016: Direct Puppet and Application Management for the Puppet Plat...
Puppet
 
PDF
APIdays Helsinki 2019 - gRPC: Lightning Fast, Self-Documenting APIs with Moha...
apidays
 
PPTX
Selenium-4
Manoj Kumar Kumar
 
Debug production server by counter
Roy Chung-Cheng Lou
 
Serverless Computing With Azure Functions
Jaliya Udagedara
 
DevNation Workshop: Object detection with Red Hat OpenShift Data Science [Mar...
Red Hat Developers
 
The IMPACT Interoperability Framework - Workflows for OCR and beyond
cneudecker
 
API Versioning in the Cloud
Cloud Elements
 
[Kotlin Serverless 工作坊] 單元 2 - 簡介 Kotlin Serverless
Shengyou Fan
 
Going Serverless with Iron.io
Isak Rickyanto
 
Azure Durable Functions
Karthikeyan VK
 
Bluetooth low energy
Alex Hihi
 
A lap around azure function proxy
Wagner Silveira
 
HAProxyConf 2019: Building a Service Mesh at Criteo with Consul and HAProxy
Pierre Souchay
 
Building Apps with MySpace SDKs
MySpaceDevTeam
 
2019 05-28 SRE Consul Criteo Meetup
Pierre Souchay
 
Microservices:
 The phantom menace
. Istio Service Mesh: 
the new hope
Sergii Bishyr
 
PuppetConf 2016: Direct Puppet and Application Management for the Puppet Plat...
Puppet
 
APIdays Helsinki 2019 - gRPC: Lightning Fast, Self-Documenting APIs with Moha...
apidays
 
Selenium-4
Manoj Kumar Kumar
 

Similar to Fancy Features in Asp.Net Core SignalR (20)

PPTX
Real-Time Communication
ssusere19c741
 
PPTX
Building Real Time Applications with ASP.NET SignalR 2.0 by Rachel Appel
.NET Conf UY
 
PPTX
Real time Communication with Signalr (Android Client)
Deepak Gupta
 
PPTX
Chat application with Azure SignalR Service
Krunal Trivedi
 
PPTX
ASP.NET MVC 5 and SignalR 2
Jaliya Udagedara
 
PPT
Getting started with ASPNET Core SignalR
Nemi Chand
 
PPTX
How To Build Real-Time Applications With ASP.NET Core SignalR
IntelliSource Technologies
 
PPTX
SignalR
LearningTech
 
PPTX
signalr
Owen Chen
 
PPTX
SignalR tutorial & best practices
Minh Ng
 
PPTX
SignalR with asp.net
Martin Bodocky
 
PPTX
Xamarin Form using ASP.NET Core SignalR client
Chen Yu Pao
 
PDF
How SignalR Can Simplify Your Messaging Needs? | Virtuoso Infotech
VirtuosoInfotech
 
PPTX
SignalR: Above & Beyond Chat
David Pine
 
PPTX
SignalR Overview
Michael Sukachev
 
PPTX
Signal r
Vasilios Kuznos
 
PPTX
Signal r core workshop - netconf
Miguel Angel Teheran Garcia
 
PPTX
Real Time Apps with SignalR Core
Sam Basu
 
PPTX
Real-time Communication using SignalR and cloud
Radu Vunvulea
 
PDF
SignalR
Sarvesh Kushwaha
 
Real-Time Communication
ssusere19c741
 
Building Real Time Applications with ASP.NET SignalR 2.0 by Rachel Appel
.NET Conf UY
 
Real time Communication with Signalr (Android Client)
Deepak Gupta
 
Chat application with Azure SignalR Service
Krunal Trivedi
 
ASP.NET MVC 5 and SignalR 2
Jaliya Udagedara
 
Getting started with ASPNET Core SignalR
Nemi Chand
 
How To Build Real-Time Applications With ASP.NET Core SignalR
IntelliSource Technologies
 
SignalR
LearningTech
 
signalr
Owen Chen
 
SignalR tutorial & best practices
Minh Ng
 
SignalR with asp.net
Martin Bodocky
 
Xamarin Form using ASP.NET Core SignalR client
Chen Yu Pao
 
How SignalR Can Simplify Your Messaging Needs? | Virtuoso Infotech
VirtuosoInfotech
 
SignalR: Above & Beyond Chat
David Pine
 
SignalR Overview
Michael Sukachev
 
Signal r
Vasilios Kuznos
 
Signal r core workshop - netconf
Miguel Angel Teheran Garcia
 
Real Time Apps with SignalR Core
Sam Basu
 
Real-time Communication using SignalR and cloud
Radu Vunvulea
 
Ad

Recently uploaded (20)

PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PDF
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PPTX
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
PPTX
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
PPTX
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
PDF
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
Tally software_Introduction_Presentation
AditiBansal54083
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
Ad

Fancy Features in Asp.Net Core SignalR