Introduction
Real-time communication has become an essential part of modern web applications. Live dashboards, notifications, monitoring systems, collaborative interfaces, and messaging applications all need mechanisms for delivering information from the server to connected browsers without requiring users to refresh the page.
ASP.NET Core SignalR is one of the most recognized solutions for real-time communication in the .NET ecosystem. It provides an abstraction over different communication transports and makes it easier to build applications that exchange messages between servers and connected clients.
WebForms Core (WFC), developed by Elanat in 2024, approaches this subject from a different architectural perspective. Rather than treating real-time communication as an independent messaging layer, WFC integrates WebSocket and Server-Sent Events (SSE) into its Server-Orchestrated UI execution model.
This creates an important distinction:
SignalR is primarily designed to facilitate real-time communication. WebForms Core can use real-time communication to deliver executable UI commands that WebFormsJS applies directly to the browser's DOM.
The difference is not simply about which technology supports WebSocket or SSE. It is about what happens after a message reaches the browser.
Two Different Architectural Goals
Before comparing their implementations, it is important to understand that WebForms Core and SignalR do not operate at exactly the same architectural level.
ASP.NET Core SignalR: A Real-Time Communication Framework
SignalR provides a structured communication system between servers and connected clients. Its central abstraction is the Hub, which allows clients to invoke server methods and servers to invoke client-side methods.
A typical SignalR application requires registering the SignalR services, mapping a Hub endpoint, defining Hub methods, and establishing a connection through a SignalR client library.
For example, the server configuration can look like this:
builder.Services.AddSignalR();
app.MapHub<ChatHub>("/chat");
A simple Hub might be implemented as follows:
public class ChatHub : Hub
{
public async Task SendMessage(
string user,
string message)
{
await Clients.All.SendAsync(
"ReceiveMessage",
user,
message
);
}
}
The JavaScript client then establishes a connection and registers a handler:
const connection =
new signalR.HubConnectionBuilder()
.withUrl("/chat")
.build();
connection.on("ReceiveMessage", (user, message) => {
console.log(user, message);
});
await connection.start();
This is a straightforward and powerful approach for applications that need a dedicated real-time communication system.
However, SignalR does not inherently understand the HTML DOM or provide a built-in mechanism for executing server-generated UI commands. If a server message is supposed to update a dashboard, insert an element, change a component, or remove a notification, the client application must implement the corresponding handlers and DOM operations, or delegate them to another UI framework.
In other words, SignalR delivers the communication mechanism. The application still decides what the received message means for its interface.
WebForms Core: Real-Time Communication as Part of UI Execution
WebForms Core follows a different model.
WFC is a server-side UI manipulation technology based on command flow rather than data flow. The server generates Action Controls through the WebForms class, and WebFormsJS receives and executes those commands directly against the browser's HTML DOM.
Its general execution model is:
Server → WebForms Class → Action Controls → WebFormsJS → HTML DOM
This architecture also applies to real-time communication.
When WebSocket or SSE is used, the server can send Action Controls through the established connection. WebFormsJS receives those commands and executes them without requiring the developer to create a separate JavaScript message handler for every UI operation.
This is particularly useful when the server needs to update an interface periodically or immediately after an internal event occurs.
WebSocket and SSE Integration in WebForms Core
WebForms Core supports both WebSocket and Server-Sent Events. They serve different communication requirements:
- WebSocket provides bidirectional communication between the client and server.
- SSE provides a persistent, one-way communication channel from the server to the client.
The WebForms class provides methods for activating and configuring these connections. WebFormsJS handles the corresponding client-side connection behavior automatically when the generated Action Controls are executed.
The developer does not need to manually create a JavaScript WebSocket or EventSource object for each interaction.
1. WebSocket
WebSocket is useful when an application needs communication in both directions. For example, a user can submit information through a WebSocket connection, while the server can also send updates or commands to that user.
WebForms Core provides methods such as:
WebForms form = new WebForms();
form.EnableWebSocket();
form.SetWebSocketEvent(
"SendButton",
HtmlEvent.OnClick,
"/socket"
);
Write(form.Response());
The SetWebSocketEvent method connects a browser event to a WebSocket endpoint. The EnableWebSocket method enables subsequent WebForms Core requests to operate through the WebSocket protocol. Other methods include EnableWebSocketOnce, AddWebSocket, DeleteWebSocket, and UseWebSocket.
WebFormsJS manages the client-side connection and the associated operations. Form submission through WebSocket is also supported, including the use of the usewebsocket attribute.
The important point is that WebForms Core does not attempt to replace the backend's WebSocket implementation. The backend must provide a compatible WebSocket endpoint and handle the server-side communication logic.
The responsibilities are separated:
- WebForms Core: Generates the instructions required to activate and use WebSocket communication.
- WebFormsJS: Establishes and manages the browser-side connection and handles client-side WebForms operations.
- Backend: Receives and processes messages, manages connections and recipients, and decides which clients should receive messages.
This separation allows WebForms Core to integrate with different backend implementations rather than requiring developers to adopt a dedicated communication framework.
2. Server-Sent Events
SSE is particularly useful when the server needs to continuously send updates to the browser without requiring a bidirectional connection.
WebForms Core provides a simple API for connecting an HTML event to an SSE endpoint:
WebForms form = new WebForms();
form.SetSSEEvent(
"TimeButton",
HtmlEvent.OnClick,
"/sse/gettime"
);
Write(form.Response());
When the user clicks the button, WebFormsJS automatically establishes the SSE connection.
The backend activates SSE for the corresponding endpoint:
public partial class GetTimeSSEController
: CodeBehindController
{
public void PageLoad(HttpContext context)
{
EnableSSE();
}
}
Once the connection is established, the backend can periodically generate and broadcast Action Controls.
For example:
var form = new WebForms();
string serverTime =
DateTime.Now.ToString("HH:mm:ss");
form.SetText(
"TimeResult",
$"Current Server Time: {serverTime}"
);
BroadcastSSE(
context,
form.ExportToLineBreak()
);
The server does not send a JavaScript instruction that must be interpreted by a custom client-side handler. It sends the Action Controls generated by the WebForms class.
WebFormsJS receives the message and executes SetText against the element identified by TimeResult.
The official CodeBehind example demonstrates this pattern with updates sent every five seconds. The same approach can be used for stock prices, notifications, server statistics, monitoring information, and other dynamic content.
For production applications, recurring work should be managed through an appropriate background service or task lifecycle rather than an unmanaged infinite loop.
3. Sending to Specific Recipients
Real-time communication is not only about establishing connections. In multi-user applications, the backend must also decide who receives each message.
CodeBehind provides SSE broadcasting methods for different recipient scopes:
// Broadcast to all connected clients
BroadcastSSE(context, message);
// Broadcast to a specific role
BroadcastSSEForRole(
context,
message,
roleName
);
// Broadcast to a specific SSE connection
BroadcastSSEForSSEId(
context,
message,
sseId
);
// Broadcast to a specific client
BroadcastSSEForClientId(
context,
message,
clientId
);
There is also an overload that supports filtering by role, ID, and client ID.
These methods are available from the Controller, Model, and View sections of CodeBehind. This makes it possible to send real-time updates from different parts of the backend without having to implement client-side message routing.
CodeBehind also provides WebSocket connection management. In this architecture, recipient selection and connection management belong to the backend. Depending on the backend implementation, messages can be directed using identifiers such as ClientID, connection names, RoleGroup, or All.
WebForms Core connects this backend functionality to WebFormsJS. It does not independently implement the backend's recipient-management system.
The Important Difference: Sending Data vs. Sending Executable UI Commands
This is where WebForms Core offers a particularly interesting approach.
Consider a live dashboard displaying the current number of active users, recent transactions, server status, and incoming notifications.
With a conventional real-time messaging approach, the server might send a JSON message:
{
"activeUsers": 124,
"status": "online"
}
The client must receive this message, interpret its structure, locate the relevant elements, and update the interface.
With SignalR, this typically involves registering a client-side handler:
connection.on("DashboardUpdate", data => {
document.getElementById("ActiveUsers")
.textContent = data.activeUsers;
document.getElementById("ServerStatus")
.textContent = data.status;
});
This is perfectly reasonable, and SignalR is not limited to JSON messages or this particular implementation. Developers can send different payloads and build their own client-side execution systems.
However, this is not what WebForms Core is primarily designed to do.
In WFC, the server can generate the actual UI operations:
var form = new WebForms();
form.SetText("ActiveUsers", "124");
form.SetText("ServerStatus", "online");
BroadcastSSE(
context,
form.ExportToLineBreak()
);
WebFormsJS receives the Action Controls and executes them directly.
There is no need to write a separate JavaScript handler for DashboardUpdate, manually extract each property, and translate it into DOM operations.
The server already knows what needs to change and generates the corresponding commands.
This is a fundamental architectural difference:
SignalR delivers messages that application code can use to update the interface. WebForms Core can deliver the UI operations themselves.
Periodic Updates and Server-Triggered Events
One of the strongest use cases for combining WebForms Core with WebSocket or SSE is the ability to send Action Controls whenever something happens on the server.
This is not limited to a fixed interval.
Consider a monitoring application. The server may need to update the interface when:
- A new database record is created.
- A transaction is completed.
- A background job changes its status.
- A user joins or leaves a system.
- A server resource exceeds a threshold.
- A notification becomes available.
- A scheduled process reaches a particular stage.
In each case, the backend can create a WebForms object, generate the required Action Controls, and send them through an existing real-time connection.
For example, when a background job completes:
var form = new WebForms();
form.SetText("JobStatus", "Completed");
form.SetStyle(
"JobStatus",
"color",
"green"
);
form.AddClass("JobStatus", "completed");
BroadcastSSE(
context,
form.ExportToLineBreak()
);
The browser does not need to know how the background job works or how its completion is detected. It only needs to receive and execute the commands.
This makes WebForms Core particularly suitable for server-driven dashboards and interfaces where the server is responsible for determining when and how the UI should change.
SignalR can certainly transport the same information. A developer could even define a custom protocol that sends commands instead of ordinary application data. But that would require building or integrating a command interpreter on the client side. SignalR itself does not provide the WebForms Core Action Control execution model.
SignalR's Strengths
A fair comparison must also recognize that SignalR offers capabilities that are not the primary focus of WebForms Core.
Hub Abstraction
SignalR provides a structured Hub model for communication between clients and servers. Clients can invoke server methods, and servers can invoke client methods.
This is especially useful for chat systems, collaborative applications, and services that expose many real-time operations.
Transport Negotiation and Fallback
SignalR supports multiple transports, including WebSocket, Server-Sent Events, and Long Polling. It can negotiate an appropriate transport based on the client, server, and environment.
This is valuable when applications must support different network conditions or hosting environments.
Connection and Group Management
SignalR provides built-in abstractions for targeting individual connections, users, and groups.
This is a major advantage when the application is primarily a real-time messaging system with complex communication requirements.
Reconnection and Stateful Reconnection
SignalR provides client-side reconnection options, including withAutomaticReconnect() for JavaScript clients. Automatic reconnection is opt-in rather than enabled by default.
Newer ASP.NET Core versions also support optional stateful reconnect, which can buffer messages and attempt to recover messages sent during temporary disconnections.
Protocols and Scaling
SignalR supports JSON and MessagePack Hub protocols and offers integration options for scaling applications, including Redis backplanes and Azure SignalR Service.
These features make SignalR a mature choice for applications that need a dedicated, feature-rich real-time communication infrastructure.
Comparison
| Feature | WebForms Core + CodeBehind | ASP.NET Core SignalR |
|---|---|---|
| Primary purpose | Server-orchestrated UI execution | Real-time communication |
| WebSocket support | Yes | Yes |
| SSE support | Yes | Yes |
| Long Polling | Not a core WFC transport | Yes |
| Client connection management | Managed by WebFormsJS through WebForms instructions | Managed by SignalR client |
| Server-to-client communication | Action Controls can be sent directly | Hub messages and client method invocations |
| Direct DOM command execution | Built into WebFormsJS | Requires application-side handling or another UI layer |
| Hub abstraction | Not required | Core abstraction |
| Recipient management | Backend responsibility; CodeBehind provides broadcasting APIs | Built-in connection, user, and group abstractions |
| Automatic transport negotiation | Not the central WFC model | Supported |
| Stateful reconnect | Depends on the underlying implementation | Supported as an opt-in feature in newer versions |
| UI-specific JavaScript handlers | Not required for standard Action Control execution | Usually required for UI updates |
When Should You Choose Each Technology?
The choice depends on the application's primary requirements.
Choose SignalR When:
- You need a dedicated real-time messaging infrastructure.
- Your application relies heavily on Hub methods and client-to-server RPC.
- You need built-in user and group communication abstractions.
- Transport negotiation and fallback are important.
- You need SignalR's ecosystem, integrations, and scaling options.
- Your real-time communication is independent of the UI technology.
Choose WebForms Core When:
- The main goal is to update the browser interface from the server.
- You want to send executable UI commands rather than repeatedly designing message handlers.
- You need periodic or event-triggered UI updates.
- You want to use WebSocket or SSE without writing separate JavaScript connection code for each interaction.
- Your backend already provides WebSocket or SSE infrastructure.
- You want real-time communication to be integrated into a Server-Orchestrated UI architecture.
These technologies are not necessarily mutually exclusive. A system can use SignalR for general-purpose real-time messaging and WebForms Core for server-orchestrated UI manipulation where both are appropriate.
Conclusion
ASP.NET Core SignalR and WebForms Core solve related but different problems.
SignalR provides a comprehensive infrastructure for real-time communication. It abstracts connections, transports, Hub invocations, and recipient management, making it a strong choice for applications whose primary requirement is exchanging messages between connected clients and servers.
WebForms Core takes a different approach. It integrates WebSocket and SSE into a command-based UI architecture. The server can generate Action Controls at regular intervals or in response to internal events, send them through an established connection, and let WebFormsJS execute them directly against the browser's DOM.
This is more than simply sending real-time data. It allows the backend to control how the interface changes without requiring developers to build a separate JavaScript layer for interpreting every message and translating it into DOM operations.
SignalR makes real-time communication easier. WebForms Core makes real-time server-orchestrated UI execution a natural part of the application architecture.
That is the fundamental difference between the two approaches.
Top comments (0)