Skip to content
IzzyBlazor

Enter all results ↑ ↓ move Esc close

Session recovery

An interactive server page runs in a session on the server. The session ends when the connection drops, the server restarts or the server runs short of memory, and the user's work is lost with it. Blazor can pause the session instead and resume it later. The resumed page restores what's in the URL or marked [PersistentState].

A pause saves the page's state in the browser and frees the server's memory. Resuming starts a new session from that state and rebuilds every component.

What comes back

  • Table and DataGrid sorting, filters, search and page. They're stored in the URL, so a resumed page shows the same rows. When you bind a grid, such as with @bind-Page, the grid restores only what your property restores.
  • Anything you bind and mark [PersistentState]. The components rebuild from it. A Dialog bound with @bind-Open opens again. A TextField or RichTextEditor shows its text again, and a grid shows its page.
  • Nothing you leave unmarked. Bound values without [PersistentState] reset, as after a reload. A file chosen in a FileUpload is also lost, because the browser can't restore it.
Orders.razor
@page "/orders"
@rendermode InteractiveServer

<DataGrid Items="Orders" @bind-Page="Page" PageSize="20">
    ...
</DataGrid>

<Dialog Title="Notes" @bind-Open="NotesOpen">
    <RichTextEditor Label="Notes" @bind-Value="Notes" />
</Dialog>

@code {
    [PersistentState] public int Page { get; set; } = 1;
    [PersistentState] public bool NotesOpen { get; set; }
    [PersistentState] public string? Notes { get; set; }
}

A persisted value must serialize to JSON. Persist only what the user would miss: what they typed, chose or opened.

The reconnect dialog

When App.razor contains a ReconnectDialog, a paused session shows "Session paused" and a Resume button. Resume starts the new session. The message states whether the server or the page paused the session. When a session can't resume, the dialog offers Reload.

Pause a hidden tab .NET 11+

.NET 11 can pause a session on its own after its tab has been hidden for a set time, and resume it when the user returns to the tab. Add the Microsoft.AspNetCore.Components.Server.AutoPause package, then turn it on where the app maps its components:

Program.cs
using Microsoft.AspNetCore.Components;   // AddAutoPause

app.MapRazorComponents<App>()
    .AddInteractiveServerRenderMode()
    .WithBrowserOptions(options =>
        options.AddAutoPause(pause => pause.HiddenDelay = TimeSpan.FromMinutes(2)));
  • The session doesn't pause while a text field or a RichTextEditor has focus, so text the user is still typing isn't lost.
  • On phones, the browser stops scripts on a background page within seconds, often before the delay runs out. The session then ends as a lost connection, and the user gets it back through the reconnect dialog.
  • When the user returns to a paused tab, it resumes on its own. The dialog shows only while it resumes.

Pause from your own code

To pause on a rule of your own, such as after a time without input, call Blazor.pauseCircuit() and Blazor.resumeCircuit() from the page's script. On .NET 11, the server can also ask a page to pause, such as before a deployment or restart. See Microsoft's pause and resume circuits (opens in a new tab).

Next steps

Connection lost

Rejoining the server…