SessionActivityTracker 1.1.1

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

SessionActivityTracker

SessionActivityTracker is a lightweight ASP.NET Core middleware and controller combo that tracks user activity enabling you to monitor and manage session timeouts effectively.

Features

  • Middleware to track activity timestamps across successful requests.
  • API Controller to retrieve the last activity information.
  • Configurable idle timeout duration to match your application.
  • Works with distributed caching (e.g., Redis, SQL Server, In-Memory).
  • Ideal for ASP.NET Core MVC apps that want to show session timeout warnings.

Getting Started

1. Install the NuGet Package

dotnet add package SessionActivityTracker

2. Configure Services in Startup.cs or Program.cs:

using SessionActivityTracker;
using SessionActivityTracker.Extensions;

// ... other services

builder.Services.AddDistributedMemoryCache(); // Or Redis/SQL distributed cache
builder.Services.AddSession();

builder.Services.AddSessionActivityTracking(options =>
{
	options.IdleTimeout = TimeSpan.FromMinutes(20); // Set your desired timeout
});

3. Add Middleware

app.UseSession();
app.UseSessionActivityTracking();

To ensure session timeout detection works accurately, you will need to prevent cookie sliding expiration on the polling endpoint.

builder.Services.ConfigureApplicationCookie(options =>
{
    
    options.SlidingExpiration = true;

    // ... other settings like LoginPath, ExpireTimeSpan, etc.
    
    options.Events.OnCheckSlidingExpiration = context =>
    {
        // Don't refresh cookie expiration when polling for session status
        if (context.Request.Path.StartsWithSegments(SessionActivityTrackingConstants.RemainingTimeEndpoint))
        {
            context.ShouldRenew = false;
        } else
        {
            context.ShouldRenew = true;
        }
        
        return Task.CompletedTask;
    };
});

API Endpoints

The standard response schema for the API endpoints is as follows:

{
    "Success": "boolean", // Indicates if the request was successful"
    "Message": "string", // Optional message
    "Data": { } // The actual data payload
}

Get Remaining Session Time

GET /api/session/remaining-time
Response
{
    "Success": true,
    "Message": "Remaining session time retrieved",
    "Data": {
	    "RemainingSeconds": 180, // Seconds remaining before session timeout
	    "IsExpired": false // Indicates if the session has expired
    }
}

Refresh Idle Timeout

POST /api/session/refresh-time
Response
{
    "Success": true,
    "Message": "Remaining session time retrieved",
    "Data": {
	    "RemainingSeconds": 1200, // Seconds remaining before session timeout
	    "IsExpired": false // Indicates if the session has expired
    }
}

License

MIT

Feedback

If you find any issues or have suggestions, please open an issue or submit a pull request on GitHub.

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 116 1/23/2026
1.1.0 202 11/25/2025
1.0.0 279 8/7/2025