Soenneker.Blazor.Utils.SessionStorage 11.0.191

Prefix Reserved
dotnet add package Soenneker.Blazor.Utils.SessionStorage --version 11.0.191
                    
NuGet\Install-Package Soenneker.Blazor.Utils.SessionStorage -Version 11.0.191
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Soenneker.Blazor.Utils.SessionStorage" Version="11.0.191" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Blazor.Utils.SessionStorage" Version="11.0.191" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Blazor.Utils.SessionStorage" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Soenneker.Blazor.Utils.SessionStorage --version 11.0.191
                    
#r "nuget: Soenneker.Blazor.Utils.SessionStorage, 11.0.191"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Soenneker.Blazor.Utils.SessionStorage@11.0.191
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Soenneker.Blazor.Utils.SessionStorage&version=11.0.191
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Blazor.Utils.SessionStorage&version=11.0.191
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

Soenneker.Blazor.Utils.SessionStorage

Reads and writes browser sessionStorage from Blazor, with string and JSON-serialized typed APIs.

Install

dotnet add package Soenneker.Blazor.Utils.SessionStorage

Register the scoped services in Program.cs:

using Soenneker.Blazor.Utils.SessionStorage.Registrars;

builder.Services.AddSessionStorageUtilAsScoped();

Inject the higher-level utility into a component or service:

@using Soenneker.Blazor.Utils.SessionStorage.Abstract
@inject ISessionStorageUtil SessionStorage

Strings

await SessionStorage.Set("checkout.step", "shipping", cancellationToken);

string? step = await SessionStorage.Get("checkout.step", cancellationToken);

Get returns null when the key does not exist. Keys must contain at least one non-whitespace character, and string values cannot be null.

Typed values

The generic overloads serialize values with System.Text.Json web defaults:

public sealed record CheckoutDraft(string Email, int ItemCount);

var draft = new CheckoutDraft("buyer@example.com", 3);
await SessionStorage.Set("checkout.draft", draft, cancellationToken);

CheckoutDraft? restored =
    await SessionStorage.Get<CheckoutDraft>("checkout.draft", cancellationToken);

A missing key, stored JSON null, or an empty/whitespace stored value returns default(T). Malformed JSON or a value incompatible with T throws JsonException. Generic string calls use the raw string representation rather than JSON quoting.

Inspect and remove entries

bool exists = await SessionStorage.ContainsKey("checkout.draft", cancellationToken);
int count = await SessionStorage.GetLength(cancellationToken);
IReadOnlyList<string> keys = await SessionStorage.GetKeys(cancellationToken);

await SessionStorage.Remove("checkout.draft", cancellationToken);

GetKeys follows the browser's storage index order; do not treat it as sorted.

Clear removes every sessionStorage entry for the current origin, including entries created by other code:

await SessionStorage.Clear(cancellationToken);

Initialize is optional. Normal operations import the JavaScript module on demand; call it during component initialization only when you want to pay that cost ahead of the first storage operation.

Browser behavior and security

  • sessionStorage is scoped to the current origin and top-level browser tab. It survives reloads but is cleared when the tab's page session ends.
  • Browser privacy settings, storage policy, or quota limits can make an operation fail; the browser exception is propagated to the caller.
  • Storage is unavailable during server prerendering. Invoke this utility only after the component can perform JavaScript interop.
  • Values are not encrypted. Any script running on the origin can read them, so do not store access tokens, passwords, or other secrets here.
  • Cancellation stops the .NET wait but cannot undo a browser storage mutation that already completed.

Storage implementation

ISessionStorageUtil provides string and typed storage operations directly through Librarian. The utility and module importer are scoped and disposed by dependency injection; Librarian supplies the browser JavaScript.

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
11.0.191 0 11/15/2026
11.0.190 0 11/15/2026
11.0.189 41 11/14/2026
11.0.188 55 11/13/2026
11.0.187 53 11/13/2026
11.0.186 48 11/13/2026
11.0.185 53 11/12/2026
11.0.184 58 11/12/2026
11.0.183 56 11/12/2026
11.0.182 48 11/12/2026
11.0.181 53 11/12/2026
11.0.180 48 11/11/2026
11.0.179 55 11/11/2026
11.0.178 51 11/11/2026
11.0.177 54 11/11/2026
11.0.176 53 11/11/2026
11.0.175 63 11/11/2026
11.0.173 103 11/9/2026
11.0.172 94 11/9/2026
11.0.171 90 11/8/2026
Loading failed

Update dependency Soenneker.Librarian.SessionStorage to 11.0.223 (#867)