DEV Community

Cover image for nderstanding Reverse Proxy with .NET & SignalR (With Source Code + ZIP)
Morteza Jangjoo
Morteza Jangjoo

Posted on

nderstanding Reverse Proxy with .NET & SignalR (With Source Code + ZIP)

Reverse Proxy plays a critical role in modern web architecture — especially when building real-time applications using SignalR.
In this guide, we’ll break down what a reverse proxy is, why you need it, and how to use it with .NET + YARP + SignalR.

Fully working example
Client → Proxy → SignalR architecture
ZIP source code included


What is a Reverse Proxy?

A reverse proxy is a server that sits in front of your backend services and forwards client requests to them.

Key benefits:

  • Load balancing
  • SSL termination
  • Central authentication & security
  • WebSockets support (important for SignalR!)
  • Routing multiple services under one public endpoint

📡 Why use Reverse Proxy with SignalR?

When building real-time systems (trading apps, dashboards, chat, IoT streaming) you may need:

Challenge Reverse Proxy Solution
Clients change endpoints? One static external URL ✅
SSL offload? Proxy handles certs ✅
Distribute load? Proxy balances hubs ✅
Run multiple backend instances? Cluster routing ✅

Architecture

Client → Reverse Proxy (YARP) → SignalR Server 
Enter fullscreen mode Exit fullscreen mode

Full Example

We will run:

App Port
SignalR Server 5000
YARP Reverse Proxy 6000
Client connects to proxy

Folder Structure

ReverseProxyDemo/ ├── SignalRServer // .NET real-time server ├── ReverseProxy // YARP proxy └── SignalRClient // Console test client 
Enter fullscreen mode Exit fullscreen mode

Code — SignalR Server (/SignalRServer/Program.cs)

using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.SignalR; var builder = WebApplication.CreateBuilder(args); builder.Services.AddSignalR(); var app = builder.Build(); app.MapGet("/", () => "SignalR Server Running"); app.MapHub<ChatHub>("/hub/chat"); app.Run(); public class ChatHub : Hub { } 
Enter fullscreen mode Exit fullscreen mode

Code — YARP Reverse Proxy (/ReverseProxy/Program.cs)

var builder = WebApplication.CreateBuilder(args); builder.Services.AddReverseProxy().LoadFromConfig(builder.Configuration.GetSection("ReverseProxy")); var app = builder.Build(); app.MapReverseProxy(); app.Run(); 
Enter fullscreen mode Exit fullscreen mode

appsettings.json

{ "ReverseProxy": { "Routes": { "signalrRoute": { "ClusterId": "signalrCluster", "Match": { "Path": "/hub/{**catch-all}" } } }, "Clusters": { "signalrCluster": { "Destinations": { "destination1": { "Address": "http://localhost:5000" } } } } } } 
Enter fullscreen mode Exit fullscreen mode

Code — Client (/SignalRClient/Program.cs)

using Microsoft.AspNetCore.SignalR.Client; Console.WriteLine("Client connecting..."); var connection = new HubConnectionBuilder() .WithUrl("http://localhost:6000/hub/chat") .Build(); await connection.StartAsync(); Console.WriteLine("Connected to SignalR via Reverse Proxy!"); 
Enter fullscreen mode Exit fullscreen mode

Running the project

Start SignalR server

cd SignalRServer dotnet run --urls=http://localhost:5000 
Enter fullscreen mode Exit fullscreen mode

Start Reverse Proxy

cd ReverseProxy dotnet run --urls=http://localhost:6000 
Enter fullscreen mode Exit fullscreen mode

Start Client

cd SignalRClient dotnet run 
Enter fullscreen mode Exit fullscreen mode

Output:

Client connecting... Connected to SignalR via Reverse Proxy! 
Enter fullscreen mode Exit fullscreen mode

Download Full Source Code (ZIP)

Link: (https://github.com/Morteza-Jangjoo/Reverse_Proxy)

This ZIP contains all three projects ready to run.


Conclusion

Reverse Proxy is essential in modern .NET architectures — especially when building real-time SignalR apps.

With YARP you get:

WebSockets support
Load balancing
Easy routing
Production-ready reverse proxy


Next Step

Want the same setup with:

  • Docker + Nginx
  • Angular real-time dashboard
  • Kubernetes setup

Comment below and I’ll publish part 2


💬 Feedback

If this helped you, drop a ❤️ and follow for more .NET + Realtime + Cloud tutorials.

Top comments (0)