Blazor Development with .NET 9 Print

  • 0

Overview

Blazor in .NET 9 brings significant improvements to both Server and WebAssembly hosting models, with enhanced rendering capabilities and better performance.

Blazor Hosting Models in .NET 9

Blazor Server

  • Runs on server, UI updates via SignalR
  • Fast initial load
  • Requires constant connection

Blazor WebAssembly

  • Runs in browser via WebAssembly
  • Offline capable
  • Larger initial download

Blazor Web App (Unified)

  • Combines Server and WASM
  • Flexible render modes per component
  • Best of both worlds

.NET 9 Blazor Improvements

Render Modes

  • Static SSR: Pre-rendered HTML, no interactivity
  • Interactive Server: SignalR-based
  • Interactive WebAssembly: Client-side
  • Interactive Auto: Server first, then WASM

Enhanced Streaming Rendering

Better progressive page loading:

@attribute [StreamRendering]

@code {
    // Content streams as it becomes available
}

Improved Reconnection

Better handling of connection issues in Blazor Server with automatic reconnection UI.

Creating a Blazor .NET 9 Project

Blazor Web App:

dotnet new blazor -o MyBlazorApp -f net9.0

Blazor WebAssembly Standalone:

dotnet new blazorwasm -o MyWasmApp -f net9.0

Deploying Blazor to Plesk

Blazor Server / Blazor Web App:

  1. Publish: dotnet publish -c Release
  2. Upload to Plesk httpdocs
  3. Configure .NET Core in Plesk
  4. Set startup file to your DLL

Blazor WebAssembly (Standalone):

  1. Publish: dotnet publish -c Release
  2. Upload publish/wwwroot contents to httpdocs
  3. Add web.config for URL rewriting (see below)

web.config for Blazor WASM:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="SPA" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="index.html" />
        </rule>
      </rules>
    </rewrite>
    <staticContent>
      <mimeMap fileExtension=".wasm" mimeType="application/wasm" />
      <mimeMap fileExtension=".dll" mimeType="application/octet-stream" />
    </staticContent>
  </system.webServer>
</configuration>

Common Blazor .NET 9 Patterns

Setting Render Mode:

@rendermode InteractiveServer
@* or *@
@rendermode InteractiveWebAssembly
@* or *@
@rendermode InteractiveAuto

Component Parameters:

[Parameter]
public string Title { get; set; }

[Parameter, EditorRequired]
public int Id { get; set; }

Troubleshooting Blazor .NET 9

Blank Page:

  • Check browser console (F12) for errors
  • Verify all files uploaded
  • Check base href in index.html

SignalR Disconnects (Server):

  • Check network stability
  • Verify WebSocket support
  • Review server logs

WASM Files 404:

  • Add MIME types in web.config
  • Ensure .wasm and .dll files uploaded

Was this answer helpful?

« Back