You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: aspnetcore/blazor/components/cascading-values-and-parameters.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -718,4 +718,4 @@ The following `ExampleTabSet` component uses the `TabSet` component, which conta
718
718
## Additional resources
719
719
720
720
*[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)
*[Prerendering support with assembly lazy loading](xref:blazor/webassembly-lazy-load-assemblies#lazy-load-assemblies-in-a-hosted-blazor-webassembly-solution)
554
554
* Razor component lifecycle subjects that pertain to prerendering
*[Prerendering support with assembly lazy loading](xref:blazor/webassembly-lazy-load-assemblies#lazy-load-assemblies-in-a-hosted-blazor-webassembly-solution)
1327
1327
* Razor component lifecycle subjects that pertain to prerendering
*[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.
426
426
427
427
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.
Copy file name to clipboardExpand all lines: aspnetcore/blazor/state-management/browser-storage.md
+28-3Lines changed: 28 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,12 +5,13 @@ description: Learn how to persist user data (state) in Blazor apps using browser
5
5
monikerRange: '>= aspnetcore-3.1'
6
6
ms.author: wpickett
7
7
ms.custom: mvc
8
-
ms.date: 07/31/2025
8
+
ms.date: 08/01/2025
9
9
uid: blazor/state-management/browser-storage
10
+
zone_pivot_groups: blazor-app-models
10
11
---
11
-
# ASP.NET Core server-side Blazor state management using browser storage
12
+
# ASP.NET Core Blazor state management using browser storage
12
13
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"
14
15
15
16
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:
16
17
@@ -499,3 +500,27 @@ In general, the *state provider parent component* pattern is recommended:
499
500
* If there's just one top-level state object to persist.
500
501
501
502
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`.
Copy file name to clipboardExpand all lines: aspnetcore/blazor/state-management/index.md
+4-7Lines changed: 4 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,19 +5,16 @@ description: Learn how to persist user data (state) in Blazor apps.
5
5
monikerRange: '>= aspnetcore-3.1'
6
6
ms.author: wpickett
7
7
ms.custom: mvc
8
-
ms.date: 07/31/2025
8
+
ms.date: 08/01/2025
9
9
uid: blazor/state-management/index
10
10
---
11
11
# ASP.NET Core Blazor state management overview
12
12
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.
14
14
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>.
16
16
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>.
21
18
22
19
The remainder of this article discusses general state management strategies for any type of Blazor app.
0 commit comments