BlazorSessionProvider 1.1.1

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

Important Notice Starting from version 1.1.0, BSP no longer stores the session ID in localStorage.

Introduction

BlazorSessionProvider is a C# .NET library for Blazor Server applications that allows you to store, retrieve, and manage server-side session state, where client–server interaction and persistent state are separate.

Features

  • πŸ“ Stateful (server) β€” the session lives on the server
  • πŸ”’ Data never travels to the client, preventing XSS
  • 🧠 Full server-side control (you can invalidate, renew, or redirect sessions)
  • πŸ” The server decides when a session expires, based on the configured settings
  • πŸ•’ | NEW | Automatic cleanup of expired sessions
  • βš™οΈ Simple configuration
  • βœ… Easy API for handling session data
  • πŸ“‘ Native integration with SignalR (keeps the session alive through the connection)
  • πŸ‘€ ClaimsPrincipal synchronized in real time (reactive to changes)
  • 🧱 State persists even if the connection reloads, or until the server closes it

Use cases for BSP

There are many use cases for BSP. Here are the most common:

  • πŸ‘€ Custom session after login β€” Stores user data (ID, role, permissions) in the session after authentication.
  • ⏰ Session timeout control β€” Automatically expires after a defined period and redirects the user to an expired-session page.
  • 🧩 Step-by-step wizard β€” Preserves data between steps of a multi-page form without relying on parameters or LocalStorage.
  • πŸ›’ Temporary shopping cart β€” Keeps the cart data on the server before checkout, avoiding exposure on the client side.
  • πŸ”— Shared context data across pages β€” Shares information between components (such as ActiveDocumentId) without using QueryString or CascadingParameters.
  • 🧠 Control of multiple SignalR connections β€” Detects if a user opens multiple tabs with the same session.

Requirements

  • This library works on .NET 8 and above.

Quick Install

  1. Install the package via NuGet
dotnet add package BlazorSessionProvider
  1. Import the library in your Program.cs file, and add the session service after created the builder
using BlazorSessionProvider;

var builder = WebApplication.CreateBuilder(args);
...
builder.Services.AddSessionProvider(config => {
  config.TimeDelay           = new TimeSpan(0, 0, 30);
  config.SessionExpiredUrl   = "/logout";
  config.SessionNotFoundUrl  = "/";
});

The session provider uses a configuration object:

  • TimeDelay is the time interval for each session to be expired
  • SessionExpiredUrl is the URL of the application to which it will redirect when the session has expired.
  • SessionNotFoundUrl is the URL of the application to which it will redirect when the application does not find the session key.

Import the library and the injection dependency on _Imports.cs

@using BlazorSessionProvider.Sessions
@inject ISessionProvider SESS

Use "InteractiveServer" on each page you want to manage your sessions:

@rendermode InteractiveServer

Or, you can use the render mode in the App.razor:

</head>
<body>
  <Routes @rendermode="InteractiveServer" />
  ...
</body>

See the Wikia. for more details.


Made with ❀️ by Oscar D. Soto

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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

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
1.1.1 104 4/20/2026
1.1.0 722 12/2/2025
1.0.4 262 6/18/2025
1.0.3 202 6/17/2025
1.0.2 200 5/2/2025
1.0.1 200 10/20/2024
1.0.0 237 1/25/2024