Soenneker.Blazor.Utils.LocalStorage
4.0.76
Prefix Reserved
See the version list below for details.
dotnet add package Soenneker.Blazor.Utils.LocalStorage --version 4.0.76
NuGet\Install-Package Soenneker.Blazor.Utils.LocalStorage -Version 4.0.76
<PackageReference Include="Soenneker.Blazor.Utils.LocalStorage" Version="4.0.76" />
<PackageVersion Include="Soenneker.Blazor.Utils.LocalStorage" Version="4.0.76" />
<PackageReference Include="Soenneker.Blazor.Utils.LocalStorage" />
paket add Soenneker.Blazor.Utils.LocalStorage --version 4.0.76
#r "nuget: Soenneker.Blazor.Utils.LocalStorage, 4.0.76"
#:package Soenneker.Blazor.Utils.LocalStorage@4.0.76
#addin nuget:?package=Soenneker.Blazor.Utils.LocalStorage&version=4.0.76
#tool nuget:?package=Soenneker.Blazor.Utils.LocalStorage&version=4.0.76
Soenneker.Blazor.Utils.LocalStorage
A scoped Blazor utility for storing strings and JSON-serialized .NET values in the browser’s localStorage.
Values persist across page loads and browser restarts for the same origin, subject to browser policy and user clearing. For tab-lifetime data, use session storage instead.
Installation
dotnet add package Soenneker.Blazor.Utils.LocalStorage
using Soenneker.Blazor.Utils.LocalStorage.Registrars;
builder.Services.AddLocalStorageUtilAsScoped();
@using Soenneker.Blazor.Utils.LocalStorage.Abstract
@inject ILocalStorageUtil LocalStorage
Storage calls require browser interop. Use the service after interactive rendering, not during server prerendering.
Store and retrieve strings
await LocalStorage.Set("myapp:theme", "dark");
string? theme = await LocalStorage.Get("myapp:theme");
bool exists = await LocalStorage.ContainsKey("myapp:theme");
Get returns null for a missing key and preserves an existing empty string. Keys must be non-empty, and stored values cannot be null.
Initialize() is optional. It eagerly loads the JavaScript module but does not read or create a storage entry.
Store typed values
public sealed record LayoutPreference(bool Compact, int PageSize);
await LocalStorage.Set(
"myapp:layout",
new LayoutPreference(Compact: true, PageSize: 25));
LayoutPreference? preference =
await LocalStorage.Get<LayoutPreference>("myapp:layout");
Non-string values are JSON-serialized with web defaults. Malformed or incompatible stored JSON causes deserialization to throw. Stored model shapes should be versioned or migrated when they change.
Get<T> returns the default value when the key is missing, when a non-string stored value is blank, or when JSON deserializes as null. Use ContainsKey when the missing-key distinction matters.
Remove and inspect entries
await LocalStorage.Remove("myapp:layout");
IReadOnlyList<string> keys = await LocalStorage.GetKeys();
int count = await LocalStorage.GetLength();
Key order is controlled by the browser and should not be used as a stable sort order. Prefix application keys, such as myapp:, to avoid collisions with other code on the same origin.
Clear removes every local-storage entry for the origin, including entries created by unrelated libraries in the same application:
await LocalStorage.Clear();
Prefer removing known, namespaced keys individually unless deleting all origin storage is explicitly intended.
Concurrency and failures
Each browser storage operation is synchronous and atomic, but a .NET read-modify-write sequence is not. Another tab can change a value between calls. This package does not expose the browser storage event or provide cross-tab locking.
Writes can throw because storage is disabled, unavailable in the browsing mode, or over quota. Large values also block the browser’s main thread during the underlying operation. Handle interop exceptions and use IndexedDB for larger datasets.
Cancellation stops waiting for Blazor interop; it cannot undo a synchronous browser write that already completed.
Security
Local storage is readable and writable by JavaScript running on the origin. Do not store passwords, bearer tokens, private keys, server session identifiers, or other high-value secrets. An XSS vulnerability can expose or modify every stored value.
Treat retrieved content as untrusted input. Validate it before using it in authorization logic, URLs, queries, file operations, or rendered output. Local storage is a client-side convenience, not an authoritative data store.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Soenneker.Blazor.Utils.ModuleImport (>= 4.0.1898)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.94 | 0 | 10/11/2026 |
| 4.0.93 | 0 | 10/11/2026 |
| 4.0.92 | 39 | 10/10/2026 |
| 4.0.91 | 45 | 10/9/2026 |
| 4.0.90 | 53 | 10/7/2026 |
| 4.0.89 | 41 | 10/7/2026 |
| 4.0.87 | 40 | 10/7/2026 |
| 4.0.86 | 915 | 10/3/2026 |
| 4.0.85 | 88 | 10/3/2026 |
| 4.0.84 | 3,428 | 9/29/2026 |
| 4.0.83 | 193 | 9/29/2026 |
| 4.0.82 | 1,720 | 9/25/2026 |
| 4.0.81 | 156 | 9/25/2026 |
| 4.0.80 | 134 | 9/25/2026 |
| 4.0.79 | 99 | 9/25/2026 |
| 4.0.78 | 551 | 9/24/2026 |
| 4.0.77 | 2,632 | 9/16/2026 |
| 4.0.76 | 98 | 9/16/2026 |
| 4.0.75 | 101 | 9/15/2026 |
| 4.0.74 | 106 | 9/14/2026 |