Skip to content

Commit f845d63

Browse files
committed
Updates
1 parent eb46f21 commit f845d63

File tree

11 files changed

+180
-199
lines changed

11 files changed

+180
-199
lines changed

aspnetcore/blazor/components/cascading-values-and-parameters.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,4 +718,4 @@ The following `ExampleTabSet` component uses the `TabSet` component, which conta
718718
## Additional resources
719719

720720
* [Generic type support: Explicit generic types based on ancestor components](xref:blazor/components/generic-type-support#explicit-generic-types-based-on-ancestor-components)
721-
* [State management: Browser storage: Factor out state preservation to a common provider](xref:blazor/state-management/browser-storage#factor-out-state-preservation-to-a-common-provider)
721+
* [State management: Browser storage: Factor out state preservation to a common provider](xref:blazor/state-management/browser-storage?pivots=server#factor-out-state-preservation-to-a-common-provider)

aspnetcore/blazor/components/integration-hosted-webassembly.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ The persisted prerendered state is transferred to the client, where it's used to
549549

550550
## Additional Blazor WebAssembly resources
551551

552-
* [State management: Browser storage: Handle prerendering](xref:blazor/state-management/browser-storage#handle-prerendering)
552+
* [State management: Browser storage](xref:blazor/state-management/browser-storage?pivots=webassembly)
553553
* [Prerendering support with assembly lazy loading](xref:blazor/webassembly-lazy-load-assemblies#lazy-load-assemblies-in-a-hosted-blazor-webassembly-solution)
554554
* Razor component lifecycle subjects that pertain to prerendering
555555
* [Component initialization (`OnInitialized{Async}`)](xref:blazor/components/lifecycle#component-initialization-oninitializedasync)
@@ -1322,7 +1322,7 @@ Additional work might be required depending on the static resources that compone
13221322
13231323
## Additional Blazor WebAssembly resources
13241324

1325-
* [State management: Browser storage: Handle prerendering](xref:blazor/state-management/browser-storage#handle-prerendering)
1325+
* [State management: Browser storage](xref:blazor/state-management/browser-storage?pivots=webassembly)
13261326
* [Prerendering support with assembly lazy loading](xref:blazor/webassembly-lazy-load-assemblies#lazy-load-assemblies-in-a-hosted-blazor-webassembly-solution)
13271327
* Razor component lifecycle subjects that pertain to prerendering
13281328
* [Component initialization (`OnInitialized{Async}`)](xref:blazor/components/lifecycle#component-initialization-oninitializedasync)

aspnetcore/blazor/components/integration.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ To resolve the problem, use ***either*** of the following approaches:
635635

636636
## Additional Blazor Server resources
637637

638-
* [State management: Browser storage: Handle prerendering](xref:blazor/state-management/browser-storage#handle-prerendering)
638+
* [State management: Browser storage: Handle prerendering](xref:blazor/state-management/browser-storage?pivots=server#handle-prerendering)
639639
* Razor component lifecycle subjects that pertain to prerendering
640640
* [Component initialization (`OnInitialized{Async}`)](xref:blazor/components/lifecycle#component-initialization-oninitializedasync)
641641
* [After component render (`OnAfterRender{Async}`)](xref:blazor/components/lifecycle#after-component-render-onafterrenderasync)
@@ -1154,7 +1154,7 @@ To resolve the problem, use ***either*** of the following approaches:
11541154

11551155
## Additional Blazor Server resources
11561156

1157-
* [State management: Browser storage: Handle prerendering](xref:blazor/state-management/browser-storage#handle-prerendering)
1157+
* [State management: Browser storage: Handle prerendering](xref:blazor/state-management/browser-storage?pivots=server#handle-prerendering)
11581158
* Razor component lifecycle subjects that pertain to prerendering
11591159
* [Component initialization (`OnInitialized{Async}`)](xref:blazor/components/lifecycle#component-initialization-oninitializedasync)
11601160
* [After component render (`OnAfterRender{Async}`)](xref:blazor/components/lifecycle#after-component-render-onafterrenderasync)
@@ -1586,7 +1586,7 @@ To resolve the problem, use ***either*** of the following approaches:
15861586

15871587
## Additional Blazor Server resources
15881588

1589-
* [State management: Browser storage: Handle prerendering](xref:blazor/state-management/browser-storage#handle-prerendering)
1589+
* [State management: Browser storage: Handle prerendering](xref:blazor/state-management/browser-storage?pivots=server#handle-prerendering)
15901590
* Razor component lifecycle subjects that pertain to prerendering
15911591
* [Component initialization (`OnInitialized{Async}`)](xref:blazor/components/lifecycle#component-initialization-oninitializedasync)
15921592
* [After component render (`OnAfterRender{Async}`)](xref:blazor/components/lifecycle#after-component-render-onafterrenderasync)
@@ -2016,7 +2016,7 @@ To resolve the problem, use ***either*** of the following approaches:
20162016

20172017
## Additional Blazor Server resources
20182018

2019-
* [State management: Browser storage: Handle prerendering](xref:blazor/state-management/browser-storage#handle-prerendering)
2019+
* [State management: Browser storage: Handle prerendering](xref:blazor/state-management/browser-storage?pivots=server#handle-prerendering)
20202020
* Razor component lifecycle subjects that pertain to prerendering
20212021
* [Component initialization (`OnInitialized{Async}`)](xref:blazor/components/lifecycle#component-initialization-oninitializedasync)
20222022
* [After component render (`OnAfterRender{Async}`)](xref:blazor/components/lifecycle#after-component-render-onafterrenderasync)

aspnetcore/blazor/components/prerender.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,6 @@ Prerendering guidance is organized in the Blazor documentation by subject matter
422422
* [Secure a SignalR hub](xref:blazor/security/webassembly/additional-scenarios#secure-a-signalr-hub)
423423
* [Interactive server-side rendering: Cross-site scripting (XSS)](xref:blazor/security/interactive-server-side-rendering#cross-site-scripting-xss)
424424

425-
* [State management: Browser storage: Handle prerendering](xref:blazor/state-management/browser-storage#handle-prerendering): Besides the *Handle prerendering* section, several article sections in the [State management node](xref:blazor/state-management/index) include remarks on prerendering.
425+
* [State management: Browser storage: Handle prerendering](xref:blazor/state-management/browser-storage?pivots=server#handle-prerendering): Besides the *Handle prerendering* section, several article sections in the [State management node](xref:blazor/state-management/index) include remarks on prerendering.
426426

427427
For .NET 7 or earlier, see [Blazor WebAssembly security additional scenarios: Prerendering with authentication](xref:blazor/security/webassembly/additional-scenarios?view=aspnetcore-7.0&preserve-view=true#prerendering-with-authentication). After viewing the content in this section, reset the documentation article version selector dropdown to the latest .NET release version to ensure that documentation pages load for the latest release on subsequent visits.

aspnetcore/blazor/state-management/browser-storage.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ description: Learn how to persist user data (state) in Blazor apps using browser
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: wpickett
77
ms.custom: mvc
8-
ms.date: 07/31/2025
8+
ms.date: 08/01/2025
99
uid: blazor/state-management/browser-storage
10+
zone_pivot_groups: blazor-app-models
1011
---
11-
# ASP.NET Core server-side Blazor state management using browser storage
12+
# ASP.NET Core Blazor state management using browser storage
1213

13-
*This article applies to server-side Blazor apps, Blazor Web Apps and Blazor Server apps. For guidance on Blazor WebAssembly apps, see <xref:blazor/state-management/webassembly#browser-storage>.*
14+
:::zone pivot="server"
1415

1516
For transient data that the user is actively creating, a commonly used storage location is the browser's [`localStorage`](https://developer.mozilla.org/docs/Web/API/Window/localStorage) and [`sessionStorage`](https://developer.mozilla.org/docs/Web/API/Window/sessionStorage) collections:
1617

@@ -499,3 +500,27 @@ In general, the *state provider parent component* pattern is recommended:
499500
* If there's just one top-level state object to persist.
500501

501502
To persist many different state objects and consume different subsets of objects in different places, it's better to avoid persisting state globally.
503+
504+
:::zone-end
505+
506+
:::zone pivot="webassembly"
507+
508+
For transient data that the user is actively creating, a commonly used storage location is the browser's [`localStorage`](https://developer.mozilla.org/docs/Web/API/Window/localStorage) and [`sessionStorage`](https://developer.mozilla.org/docs/Web/API/Window/sessionStorage) collections:
509+
510+
* `localStorage` is scoped to the browser's instance. If the user reloads the page or closes and reopens the browser, the state persists. If the user opens multiple browser tabs, the state is shared across the tabs. Data persists in `localStorage` until explicitly cleared. The `localStorage` data for a document loaded in a "private browsing" or "incognito" session is cleared when the last "private" tab is closed.
511+
* `sessionStorage` is scoped to the browser tab. If the user reloads the tab, the state persists. If the user closes the tab or the browser, the state is lost. If the user opens multiple browser tabs, each tab has its own independent version of the data.
512+
513+
> [!NOTE]
514+
> `localStorage` and `sessionStorage` can be used in Blazor WebAssembly apps but only by writing custom code or using a third-party package.
515+
516+
Generally, `sessionStorage` is safer to use. `sessionStorage` avoids the risk that a user opens multiple tabs and encounters the following:
517+
518+
* Bugs in state storage across tabs.
519+
* Confusing behavior when a tab overwrites the state of other tabs.
520+
521+
`localStorage` is the better choice if the app must persist state across closing and reopening the browser.
522+
523+
> [!WARNING]
524+
> Users may view or tamper with the data stored in `localStorage` and `sessionStorage`.
525+
526+
:::zone-end

aspnetcore/blazor/state-management/index.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,16 @@ description: Learn how to persist user data (state) in Blazor apps.
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: wpickett
77
ms.custom: mvc
8-
ms.date: 07/31/2025
8+
ms.date: 08/01/2025
99
uid: blazor/state-management/index
1010
---
1111
# ASP.NET Core Blazor state management overview
1212

13-
This article and the other articles in this node describe common approaches for maintaining a user's data (state) while they use an app and across browser sessions, including during prerendering on the server.
13+
This article and the other articles in this node describe common approaches for maintaining a user's data (state) while they use an app and across browser sessions, including during server prerendering.
1414

15-
Guidance specific to server-side Blazor apps, Blazor Web Apps and Blazor Server apps, is provided in the following articles:
15+
Guidance on using browser storage is provided in <blazor/state-management/browser-storage>.
1616

17-
* <xref:blazor/state-management/server>
18-
* <blazor/state-management/browser-storage>
19-
20-
Guidance for Blazor WebAssembly apps is covered in <xref:blazor/state-management/webassembly>.
17+
For guidance specific to server-side Blazor apps, see <xref:blazor/state-management/server>. For Blazor WebAssembly apps, see <xref:blazor/state-management/webassembly>.
2118

2219
The remainder of this article discusses general state management strategies for any type of Blazor app.
2320

0 commit comments

Comments
 (0)