Coding Standards

Blazor Coding Standards

Foundational

The full reference for building UIs in Blazor: components, parameters, state, lifecycle, render modes, security, forms, JS interop, and performance. Blazor shares ideas with React but has its own model, and an important security difference between Server and WebAssembly. Builds on .NET / C# Coding Standards and the same web-security rules used everywhere; pairs with the HTML, CSS, and React standards.

We use Blazor (for example the intranet and internal tooling) with the modern component model and render modes, in C# and Razor with no TypeScript. Many ideas match React Coding Standards: small composable components, one-way data flow, immutability. But Blazor's lifecycle, parameter rules, render modes, and the Server-versus-WASM trust boundary each need care.

The most important security point: in Blazor WebAssembly, all C# runs in the browser and the user can see and edit it. So it is never a trust boundary. Server-side authorization and validation are required whatever the render mode (see Web & Frontend Security, Authentication & Authorization).

Components & structure

Parameters & data flow

State, rendering & lifecycle

Render modes & hosting

Security

WASM trusts itself, mutates parameter // Blazor WebAssembly component
[Parameter] public Order Order { get; set; }
void Approve() {
if (currentUser.IsAdmin) { Order.Status = "Approved"; api.Save(Order); }
}

The IsAdmin check runs in the browser, where the user can bypass it. The API seems to trust the call, and the component mutates a parameter it does not own. Authorization must be on the server, and parameters are read-only.

Server enforces, callback up void Approve() => OnApprove.InvokeAsync(Order.Id); // ask parent or service
// server service: [Authorize(Roles="Admin")] ApproveAsync(id) — the real gate,
// re-checks tenant and state, audits the decision

The component just requests the action. The server-side service is where authorization, validation, and audit actually happen. This is safe whatever the render mode.

Forms, rendering & JS interop

Errors & testing

Self-review checklist

Why it matters: Blazor lets a .NET team build rich UIs without switching to JavaScript. But its render modes and lifecycle are easy to misuse, and the Server-versus-WebAssembly trust difference is a real security trap, because WASM code and data are fully exposed. Clear, deep standards for components, state, lifecycle, and security keep our Blazor UIs correct, fast, and safe.