Blazor Server
Blazor Server is a component-based web UI framework that runs on the server using SignalR to handle UI interactions over a real‑time connection. It enables developers to build interactive web UIs with C# instead of JavaScript while keeping a thin client footprint.
Key Features
- Full‑stack .NET development
- Server‑side rendering with real‑time UI updates
- Integrated with ASP.NET Core authentication and authorization
- Automatic reconnection and session state management
Getting Started
Create a new Blazor Server project using the .NET CLI:
dotnet new blazorserver -o MyBlazorApp
Run the application:
cd MyBlazorApp
dotnet run
Project Structure
| Folder / File | Description |
|---|---|
| _Imports.razor | Global using directives for Razor components. |
| App.razor | Root component that sets up routing. |
| Pages/ | Contains Razor pages (e.g., Index.razor, Counter.razor). |
| Shared/ | Reusable components like NavMenu and MainLayout. |
| Program.cs | Configures the host and services. |
| Startup.cs | (Optional) Additional middleware configuration. |
SignalR Connection
Blazor Server uses a persistent SignalR connection to synchronize UI events. The connection is established when a client first loads the page and is gracefully closed when the user navigates away.
Performance Considerations
- Keep component rendering lightweight.
- Use
@keyto optimize diffing when rendering lists. - Configure the SignalR hub timeout if you anticipate long‑running operations.