Soenneker.Blazor.Utils.Session
4.0.2702
Prefix Reserved
See the version list below for details.
dotnet add package Soenneker.Blazor.Utils.Session --version 4.0.2702
NuGet\Install-Package Soenneker.Blazor.Utils.Session -Version 4.0.2702
<PackageReference Include="Soenneker.Blazor.Utils.Session" Version="4.0.2702" />
<PackageVersion Include="Soenneker.Blazor.Utils.Session" Version="4.0.2702" />
<PackageReference Include="Soenneker.Blazor.Utils.Session" />
paket add Soenneker.Blazor.Utils.Session --version 4.0.2702
#r "nuget: Soenneker.Blazor.Utils.Session, 4.0.2702"
#:package Soenneker.Blazor.Utils.Session@4.0.2702
#addin nuget:?package=Soenneker.Blazor.Utils.Session&version=4.0.2702
#tool nuget:?package=Soenneker.Blazor.Utils.Session&version=4.0.2702
Soenneker.Blazor.Utils.Session
Caches Blazor WebAssembly access tokens, refreshes tokens near expiration, and optionally redirects when session activity through the utility stops.
Install
dotnet add package Soenneker.Blazor.Utils.Session
Register the scoped service in Program.cs after configuring Blazor WebAssembly authentication:
using Soenneker.Blazor.Utils.Session.Registrars;
builder.Services.AddSessionUtilAsScoped();
Inject ISessionUtil where an access token is needed:
@using Soenneker.Blazor.Utils.Session.Abstract
@inject ISessionUtil Session
string accessToken = await Session.GetAccessToken(cancellationToken);
The utility uses the registered IAccessTokenProvider. It returns a cached token while that token has at least one minute remaining; otherwise it coalesces concurrent callers into one provider request. A provider request that does not finish within 30 seconds clears local session state and redirects to the session-expired route.
Configuration
Session:Uri controls the app-local route used for expiration and token-acquisition failures. It defaults to errors/sessionexpired.
An idle timeout is optional. Session:IdleTimeoutMinutes is preferred; Session:TimeoutMinutes is accepted as a fallback.
{
"Session": {
"Uri": "account/session-expired",
"IdleTimeoutMinutes": 30
}
}
Idle activity means calls to GetAccessToken or UpdateWithAccessToken; this package does not listen for mouse, keyboard, navigation, or network activity. Omit the timeout setting, set it to 0, or use a negative value to disable idle expiration.
Update expiration explicitly
GetAccessToken records the provider token's expiration automatically. If another authentication path obtains or renews a token, supply its UTC expiration:
await Session.UpdateWithAccessToken(jwtExpiration, cancellationToken);
When the timestamp is reached, the cached token is cleared. The next GetAccessToken call asks the provider for a token again.
Clear session state
Clear the cached token and cancel expiration timers without navigating:
await Session.ClearState();
Or clear state and navigate to the configured expiration route:
await Session.ClearStateAndRedirect(error: false, cancellationToken);
The error argument controls whether the event is logged as an error or normal expiration. Redirects are suppressed after the first one in a session state cycle. Updating the access-token expiration starts a new cycle.
Operational behavior
- Clearing or disposing the session invalidates token requests already in flight; stale results cannot restore cleared state.
- Cancelling one caller stops that caller from waiting. The underlying
IAccessTokenProviderrequest may continue because its API does not accept a cancellation token. - Token-provider failures clear local state, redirect to the expiration route, and are rethrown to the caller.
- The service is intended to be scoped. Dependency injection disposes it automatically; manually created instances must be disposed.
| 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.Asyncs.Locks (>= 4.0.70)
- Soenneker.Atomics.Longs (>= 4.0.20)
- Soenneker.Blazor.Utils.Navigation (>= 4.0.1164)
- Soenneker.Extensions.Configuration (>= 4.0.861)
- Soenneker.Extensions.ValueTask (>= 4.0.119)
- Soenneker.Utils.Delay (>= 4.0.82)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Soenneker.Blazor.Utils.Session:
| Package | Downloads |
|---|---|
|
Soenneker.Blazor.ApiClient
A lightweight and efficient API client wrapper for Blazor applications, simplifying HTTP communication with support for asynchronous calls, cancellation tokens, and JSON serialization. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.2718 | 0 | 8/31/2026 |
| 4.0.2717 | 0 | 8/31/2026 |
| 4.0.2715 | 0 | 8/31/2026 |
| 4.0.2714 | 0 | 8/30/2026 |
| 4.0.2712 | 33 | 8/30/2026 |
| 4.0.2710 | 33 | 8/30/2026 |
| 4.0.2707 | 67 | 8/30/2026 |
| 4.0.2705 | 37 | 8/30/2026 |
| 4.0.2704 | 93 | 8/30/2026 |
| 4.0.2702 | 39 | 8/30/2026 |
| 4.0.2698 | 36 | 8/29/2026 |
| 4.0.2697 | 42 | 8/29/2026 |
| 4.0.2696 | 42 | 8/29/2026 |
| 4.0.2695 | 31 | 8/29/2026 |
| 4.0.2694 | 343 | 8/26/2026 |
| 4.0.2693 | 152 | 8/26/2026 |
| 4.0.2692 | 158 | 8/25/2026 |
| 4.0.2691 | 355 | 8/21/2026 |
| 4.0.2689 | 105 | 8/21/2026 |
| 4.0.2688 | 507 | 8/18/2026 |
Harden session state and improve documentation