Blazor · Foundations

Interactive Server Rendering

Interactive Server makes components respond to clicks and typing while the code keeps running on the server.

Beginner 5 min Lesson 5 of 31Examples target .NET 9 Blazor Web App.
Before you start:Blazor Architecture
0/31 in Blazor
On this page · 5 min · Beginner

Learning objectives#

  • Enable Interactive Server rendering
  • Explain circuits and their costs
  • Handle disconnection and reconnection
  • Decide when to use it

Explanation#

Register it with AddInteractiveServerComponents() and AddInteractiveServerRenderMode(), then apply @rendermode InteractiveServer to a page or component.

Each user gets a circuit: a SignalR connection plus server memory holding component state. UI events travel to the server; DOM diffs travel back.

Advantages: fast first load, full server access (databases, files), code never leaves the server. Costs: latency on every interaction, memory per user, and the UI stops when the connection drops.

Code example: Enabling Interactive Server#

C#Program.cs Illustrative
var builder = WebApplication.CreateBuilder(args);


builder.Services.AddRazorComponents()
    .AddInteractiveServerComponents();


var app = builder.Build();
app.UseStaticFiles();
app.UseAntiforgery();


app.MapRazorComponents<App>()
    .AddInteractiveServerRenderMode();


app.Run();


// In a component:  @rendermode InteractiveServer
Expected output
Components marked @rendermode InteractiveServer now handle events. The browser keeps one WebSocket open per tab.

This example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.

Step-by-step explanation#

  1. AddInteractiveServerComponents registers the server-side services.
  2. AddInteractiveServerRenderMode maps the SignalR hub endpoint.
  3. Antiforgery protection is required by Blazor Web Apps.
  4. Only components that opt in become interactive.

Real-world use case#

An internal stock management screen used by 50 staff on a company network: low latency, direct database access and no API layer needed.

Common mistakes#

Using it for high-traffic public sites without planning

Thousands of circuits need memory and sticky sessions. Consider static SSR or WebAssembly for public pages.

Ignoring reconnection

Mobile networks drop. Customise the reconnect UI and keep state you cannot lose outside the circuit.

Best practices#

  • Use for internal or low-latency apps
  • Enable WebSockets on the host
  • Use sticky sessions or Azure SignalR Service when scaling out
  • Keep per-user state small

Remember this#

Interactive Server = events over SignalR, code stays on server.

One circuit per user = memory + connection.

Fast start, but every click is a round trip.

Practice exercise#

Your task: Which two calls enable Interactive Server in Program.cs?

Show solution
C# Illustrative
builder.Services.AddRazorComponents().AddInteractiveServerComponents();
app.MapRazorComponents<App>().AddInteractiveServerRenderMode();

Mini quiz#

Interactive Server Rendering quizMultiple choice Question 1 of 1

What happens to an Interactive Server page when the network connection drops?

Score so far: 0/0

Want more? Practise all Blazor MCQs · Blazor interview questions

My notes#

Saved in this browser.

Progress is saved in this browser. Sign in to sync.