Soenneker.Blazor.Utils.Session 4.0.2724

Prefix Reserved
dotnet add package Soenneker.Blazor.Utils.Session --version 4.0.2724
                    
NuGet\Install-Package Soenneker.Blazor.Utils.Session -Version 4.0.2724
                    
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.Session" Version="4.0.2724" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Blazor.Utils.Session" Version="4.0.2724" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Blazor.Utils.Session" />
                    
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.Session --version 4.0.2724
                    
#r "nuget: Soenneker.Blazor.Utils.Session, 4.0.2724"
                    
#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.Session@4.0.2724
                    
#: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.Session&version=4.0.2724
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Blazor.Utils.Session&version=4.0.2724
                    
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

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 IAccessTokenProvider request 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.2724 31 9/3/2026
4.0.2723 140 9/1/2026
4.0.2722 58 8/31/2026
4.0.2721 167 8/31/2026
4.0.2720 75 8/31/2026
4.0.2719 128 8/31/2026
4.0.2718 107 8/31/2026
4.0.2717 56 8/31/2026
4.0.2715 58 8/31/2026
4.0.2714 54 8/30/2026
4.0.2712 68 8/30/2026
4.0.2710 59 8/30/2026
4.0.2707 279 8/30/2026
4.0.2705 61 8/30/2026
4.0.2704 164 8/30/2026
4.0.2702 58 8/30/2026
4.0.2698 61 8/29/2026
4.0.2697 63 8/29/2026
4.0.2696 65 8/29/2026
4.0.2695 55 8/29/2026
Loading failed

Update dependency Soenneker.Asyncs.Locks to 4.0.76 (#3549)