WeihanLi.Web.Extensions 2.3.2

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

WeihanLi.Web.Extensions

A curated set of practical building blocks for ASP.NET Core apps: authentication providers, endpoint filters, middleware, MVC helpers, and more.

NuGetNuGet (prerelease)Azure PipelinesGitHub Actions

Table of Contents

Features

  • Authentication providers – drop-in handlers for API key, basic, header, query string, and delegate-based schemes (AuthenticationBuilderExtension).
  • Access control helper – configure granular resource checks, tag helpers, and middleware, or promote the policy to the app default (AccessControlHelper).
  • JWT tooling – lightweight JwtTokenService for issuing/refreshing tokens with ASP.NET Core authentication integration.
  • Response filtersApiResultFilter, environment/conditional filters, and feature-flag-aware filters for consistent API responses.
  • Middleware toolset – exception handler, configuration inspector, feature-flag-based pipeline branching, health check helpers.
  • MVC utilities – strongly typed pager, plain-text formatter, tenant/user providers, and HTTP context extensions (HttpContextExtension).
  • Target frameworks – ships for net8.0, net9.0, and net10.0.

Explore the src/WeihanLi.Web.Extensions folder for the full catalog; each namespace groups related functionality (Authentication, Authorization, Filters, Middleware, Pager, etc.).

Installation

dotnet add package WeihanLi.Web.Extensions

Quick Start

var builder = WebApplication.CreateBuilder(args);

builder.Services
    .AddControllers(options =>
    {
        options.Filters.Add<ApiResultFilter>(); // standardize API responses
    })
    .AddJsonOptions();

builder.Services.AddAuthentication()
    .AddApiKey(options =>
    {
        options.ApiKeyName = "X-ApiKey";
        options.ApiKey = "super-secret-key";
    })
    .AddBasic(options =>
    {
        options.UserName = "demo";
        options.Password = "demo";
    });

builder.Services.AddAccessControlHelper<MyResourceStrategy, MyControlStrategy>(options =>
{
    options.UseAsDefaultPolicy = true;
});

var app = builder.Build();

app.UseAuthentication();
app.UseAuthorization();
app.UseAccessControlHelper(); // enable middleware support

app.MapControllers();
app.Run();

Replace MyResourceStrategy/MyControlStrategy with your own IResourceAccessStrategy/IControlAccessStrategy implementations. For a more complete walk-through, review the sample project linked below.

Usage Highlights

  • Access control – decorate MVC controllers with [AccessControl], register tag helpers, or use UseAccessControlHelper() middleware to enforce centralised policies.
  • API response shaping – apply ApiResultFilter globally, per controller, or as a minimal API endpoint filter to wrap responses with the built-in Result model.
  • Feature flags – gate middleware with app.UseIfFeatureEnabled(...) or guard actions via [FeatureFlagFilter("MyFlag")], using configuration-driven toggles.
  • Authentication mix-and-match – compose multiple schemes (AddApiKey, AddHeader, AddQuery, AddDelegate) and map policies using standard AuthorizeAttribute.
  • Developer tooling – surface configuration via app.MapConfigInspector(), enrich structured logging with HttpContextLoggingEnricher, or expose probes with app.MapProbes(...).

These helpers are additive: you can adopt a single filter or mix several features without impacting the default ASP.NET Core pipeline.

Samples and Docs

  • Sample application: samples/WeihanLi.Web.Extensions.Samples demonstrates authentication combos, endpoint filters, feature switches, and the config inspector UI.
  • Release notes: docs/ReleaseNotes.md tracks major additions for each NuGet version.
  • API reference / documentation site: build with docfx docfx.json or browse the published GitHub Pages site (if available).

Build Locally

Have the latest .NET SDK installed first, download from https://get.dot.net/

Build the project

dotnet build

To experiment quickly, run the sample:

dotnet run --project samples/WeihanLi.Web.Extensions.Samples

Contributing

Contributions are welcome—issues, feature ideas, and pull requests all help the project grow. Please discuss sizeable changes in an issue before opening a PR and ensure builds pass locally (dotnet build) before submitting.

License

This project is licensed under the Apache License 2.0.

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 is compatible.  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 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

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
2.3.2 56 1/23/2026
2.3.1 288 12/25/2025
2.3.1-preview-20251215-103353 216 12/15/2025
2.3.1-preview-20251123-015544 147 11/23/2025
2.3.1-preview-20251122-162559 204 11/22/2025
2.3.0 404 11/12/2025
2.2.0 430 9/15/2025
2.2.0-preview-20250915-102700 225 9/15/2025
2.2.0-preview-20250525-154628 188 5/25/2025
2.2.0-preview-20250423-012210 169 4/23/2025
2.1.0 1,249 1/5/2025
2.1.0-preview-20250104-105255 206 1/4/2025
2.0.0 510 11/13/2024
1.12.0 442 10/10/2024
1.11.0 317 9/8/2024
1.10.0 372 6/22/2024
1.9.0 257 6/2/2024
1.8.0 480 3/7/2024
1.7.0 1,221 11/16/2023
1.6.0 1,437 11/20/2022
1.5.0 688 11/11/2022
1.4.0 927 8/20/2022
1.4.0-preview-20220810-224612 301 8/10/2022
1.4.0-preview-20220715-130938 363 7/15/2022
1.4.0-preview-20220715-000844 356 7/15/2022
1.4.0-preview-20220715-000514 301 7/15/2022
1.3.0 1,684 3/28/2022
1.2.3 676 3/20/2022
1.2.2 594 3/17/2022
1.2.1 595 3/17/2022
1.2.0 626 3/15/2022
1.2.0-preview-20220315-115808 390 3/15/2022
1.2.0-preview-20220314-233220 349 3/14/2022
1.2.0-preview-20220312-183013 385 3/12/2022
1.2.0-preview-20220301-144416 388 3/1/2022
1.2.0-preview-20211204-074804 869 12/4/2021
1.2.0-preview-20201019-153837 1,425 10/19/2020
1.2.0-preview-20200616-041409 649 6/16/2020
1.1.1 926 6/8/2020
1.1.0 695 6/1/2020
1.1.0-preview-20200529-145026 571 5/29/2020
1.1.0-preview-20200525-104911 568 5/25/2020
1.0.1-preview-20200522-180424 556 5/22/2020
1.0.1-preview-20200521-152742 555 5/21/2020
1.0.0 4,627 12/10/2019
1.0.0-preview-20191204-054550 618 12/4/2019
1.0.0-preview-20191130-142138 606 11/30/2019
1.0.0-preview-20191011-092336 1,137 10/11/2019
1.0.0-preview-20190630-113152 1,041 6/30/2019
1.0.0-preview-20190602-094726 832 6/2/2019