DKNet

Configure trusted forwarding sources

Part of DKNet.AspCore.Extensions. AddForwardedHeadersConfig parses explicit trusted IP addresses and CIDR networks. It clears the framework’s known-proxy/network collections. Without trusted entries, forwarding is disabled. With any entries, it enables X-Forwarded-For and X-Forwarded-Proto for those sources.

using DKNet.AspCore.Extensions.Hosting;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddForwardedHeadersConfig(builder.Configuration);
var app = builder.Build();
app.UseForwardedHeadersConfig();
Console.WriteLine("ForwardedHeadersConfig pipeline configured.");

Configure trusted forwarding sources: the host registers settings and the matching Use method installs middleware only when its feature marker exists.

⚙️ Configuration reference

Configuration key Type Default Effect
Security:TrustedProxies string[] empty IPs parsed with IPAddress.Parse.
Security:TrustedNetworks string[] empty CIDRs parsed with System.Net.IPNetwork.Parse.

⚠️ Gotchas & limits