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
<PackageReference Include="WeihanLi.Web.Extensions" Version="2.3.2" />
<PackageVersion Include="WeihanLi.Web.Extensions" Version="2.3.2" />
<PackageReference Include="WeihanLi.Web.Extensions" />
paket add WeihanLi.Web.Extensions --version 2.3.2
#r "nuget: WeihanLi.Web.Extensions, 2.3.2"
#:package WeihanLi.Web.Extensions@2.3.2
#addin nuget:?package=WeihanLi.Web.Extensions&version=2.3.2
#tool nuget:?package=WeihanLi.Web.Extensions&version=2.3.2
WeihanLi.Web.Extensions
A curated set of practical building blocks for ASP.NET Core apps: authentication providers, endpoint filters, middleware, MVC helpers, and more.
Table of Contents
- Features
- Installation
- Quick Start
- Usage Highlights
- Samples and Docs
- Build Locally
- Contributing
- License
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
JwtTokenServicefor issuing/refreshing tokens with ASP.NET Core authentication integration. - Response filters –
ApiResultFilter, 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, andnet10.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 useUseAccessControlHelper()middleware to enforce centralised policies. - API response shaping – apply
ApiResultFilterglobally, per controller, or as a minimal API endpoint filter to wrap responses with the built-inResultmodel. - 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 standardAuthorizeAttribute. - Developer tooling – surface configuration via
app.MapConfigInspector(), enrich structured logging withHttpContextLoggingEnricher, or expose probes withapp.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.Samplesdemonstrates authentication combos, endpoint filters, feature switches, and the config inspector UI. - Release notes:
docs/ReleaseNotes.mdtracks major additions for each NuGet version. - API reference / documentation site: build with
docfx docfx.jsonor 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 | Versions 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. |
-
net10.0
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 10.0.2)
- WeihanLi.Common (>= 1.0.86)
-
net8.0
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 8.0.23)
- WeihanLi.Common (>= 1.0.86)
-
net9.0
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 9.0.12)
- WeihanLi.Common (>= 1.0.86)
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 | 173 | 1/23/2026 |
| 2.3.1 | 301 | 12/25/2025 |
| 2.3.1-preview-20251215-103353 | 222 | 12/15/2025 |
| 2.3.1-preview-20251123-015544 | 152 | 11/23/2025 |
| 2.3.1-preview-20251122-162559 | 212 | 11/22/2025 |
| 2.3.0 | 414 | 11/12/2025 |
| 2.2.0 | 439 | 9/15/2025 |
| 2.2.0-preview-20250915-102700 | 230 | 9/15/2025 |
| 2.2.0-preview-20250525-154628 | 194 | 5/25/2025 |
| 2.2.0-preview-20250423-012210 | 176 | 4/23/2025 |
| 2.1.0 | 1,269 | 1/5/2025 |
| 2.1.0-preview-20250104-105255 | 214 | 1/4/2025 |
| 2.0.0 | 565 | 11/13/2024 |
| 1.12.0 | 454 | 10/10/2024 |
| 1.11.0 | 330 | 9/8/2024 |
| 1.10.0 | 381 | 6/22/2024 |
| 1.9.0 | 271 | 6/2/2024 |
| 1.8.0 | 489 | 3/7/2024 |
| 1.7.0 | 1,231 | 11/16/2023 |
| 1.6.0 | 1,446 | 11/20/2022 |