aemarcoToolboxWeb 10.3.2

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

ToolboxWeb

NuGet NuGet

Successor to WebTools, which is being discontinued. Unlike WebTools, this project is not meant to become a single catch-all again — each piece here should earn its place; anything that only one consumer needs, or that's small enough to inline, belongs in that consumer instead.

Table of Contents

  1. Authentication
  2. Authorization
  3. Configuration
  4. Extensions
  5. Logging
  6. Middleware

Authentication

Adds an authentication scheme that unconditionally succeeds and stamps the caller as "Anonymous" — it performs no real check. This exists for authorization policies where identity itself isn't the gate (e.g. LAN-IP-based policies below): ASP.NET Core's pipeline always requires some authentication scheme to produce a ClaimsPrincipal before a policy's requirements run, even when the actual decision happens entirely in a requirement handler. Never register it as the default scheme.

services.AddAuthentication(...)
    .AddAnonymousScheme("Anon");

Authorization

LAN IP Authorization

Restricts access to requests originating from trusted IP ranges.

  • Loopback addresses (127.0.0.1, ::1) are always allowed.
  • RFC-1918 private ranges (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16) are trusted by default.

Register one or more named policies:

// Default: allows all RFC-1918 ranges (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16)
services.AddLanIpAddressPolicy("LanOnly");

// Custom subnets
services.AddLanIpAddressPolicy("LanOnly", opts =>
{
    opts.LocalSubnets = ["192.168.20.0/24"];
});

// Exact IPs — clears subnets and adds /32 (IPv4) or /128 (IPv6) entries; throws on invalid input
services.AddLanIpAddressPolicy("LanOnly", opts =>
{
    opts.WithIpAddresses("192.168.1.10", "192.168.1.11");
});

// Enable hairpin NAT support (allow own public IP)
services.AddLanIpAddressPolicy("LanOnly", opts =>
{
    opts.AllowOwnPublicIp = true;
});

// With a specific authentication scheme
services.AddLanIpAddressPolicy("Bearer", "LanOnly");

AllowOwnPublicIp resolves the server's own public IP via IPublicIpService, trying several external lookup services in order and caching the result. If every source fails, resolution returns null and the hairpin check is skipped for that request rather than failing open — it never auto-allows on a resolution failure.

Allowed Clients

Adds a policy which requires the client_id claim to match one of the given client IDs.

services.AddAllowedClientsPolicy("clientB", "clientB");

Policy documentation can be found at https://docs.microsoft.com/en-us/aspnet/core/security/authorization/policies

Great read around DefaultPolicy and FallbackPolicy https://scottsauber.com/2020/01/20/globally-require-authenticated-users-by-default-using-fallback-policies-in-asp-net-core

Read about Policy Conventions https://andrewlock.net/setting-global-authorization-policies-using-the-defaultpolicy-and-the-fallbackpolicy-in-aspnet-core-3

Configuration

X509 Certificate Settings

X509CertificateSettingsBase — POCO (Authority, Audience, Path, Pwd) for certificate-backed JWT bearer setups. Authority and Audience are independent settings — don't reuse one for both, or you lose the distinction between "who signed this token" and "who it's meant for". Call ApplyTo(TokenValidationParameters) to load the cert and wire up ValidIssuer/ValidAudience/IssuerSigningKey in one go:

services.AddOptions<JwtBearerOptions>(scheme)
    .Configure<CertSettings>((options, certSettings) =>
        certSettings.ApplyTo(options.TokenValidationParameters));

If you are using this (unchanged), nothing extra is needed. If you extend, you need to roll your own mapper. To use together with ToolboxAppOptions, just do:

public class CertSettings : X509CertificateSettingsBase, ISettingsBase;

OpenID Connect Settings

OpenIdConnectSettings — settings POCO that maps directly onto OpenIdConnectOptions via the generated ApplyTo() extension. If you are using this (unchanged), nothing extra is needed. If you extend, you need to roll your own mapper. To use together with ToolboxAppOptions, just do:

public class OidcSettings : OpenIdConnectSettings, ISettingsBase;
services.AddOptions<OpenIdConnectOptions>(scheme)
    .Configure<OidcSettings>((options, oidcSettings) => oidcSettings.ApplyTo(options));

Extensions

ContextExtensions — HttpContext helpers for reconstructing the request's root/base/absolute URL (GetRootPath/GetBasePath/GetAbsolutePath) and reading the caller's bearer token (GetAccessToken). GetAccessToken returns just the token — the "Bearer " scheme prefix is stripped — or null if the Authorization header isn't a bearer token at all.

Logging

SetupSerilogging

Precedence — code defaults < appsettings.json < the configure callback — is deliberate, and achieved differently per Serilog API since Serilog isn't symmetric here:

  • Enrichment properties use first-set-wins semantics, so they're applied before ReadFrom.Configuration. "app"/"EnvironmentApplicationName" are derived from app.Environment.ApplicationName rather than left config-overridable, since that's reconfigured at the builder level, not through Serilog.
  • MinimumLevel.Override uses last-set-wins semantics, so ReadFrom.Configuration runs after the code-level "Microsoft": Information default, and configure runs last of all. This is namespace-prefix matching, not glob — "Microsoft*" is a literal string matching nothing.

Same implementation as ToolboxConsole.ConsoleAppExtensions.SetupSerilogging, just on WebApplicationBuilder for the web tier instead of the console tier.

Middleware

Bearer To Header

Adds a middleware, which moves an access_token provided as query parameter, to an Authorization header for a Bearer.

app.UseBearerToHeaderMiddleware(); //move bearer from url to header before routing

Exception Middleware

Catches exceptions and writes a JSON ErrorResponse. BadRequestException maps to 400 with its message; anything else maps to 500 with a deliberately generic message — the real exception is logged, never sent to the client.

app.UseExceptionMiddleware();            // production: catches everything
app.UseDeveloperExceptionMiddleware();   // dev: BadRequestException still returns 400 JSON, everything else goes to ASP.NET's developer exception page
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

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
10.3.2 101 11/1/2026
10.2.3 105 11/1/2026
10.1.3 153 7/27/2026
10.1.2 131 7/27/2026
10.0.17 152 4/18/2026
10.0.15 143 4/18/2026
10.0.11 144 4/18/2026