Edi.AspNetCore.Utils 2.0.0

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

Edi.AspNetCore.Utils

NuGet License: MIT

Common ASP.NET Core helper classes for my own projects. Targets .NET 10.

Installation

dotnet add package Edi.AspNetCore.Utils

Features

ClientIPHelper

Returns the client IP address from HttpContext.Connection.RemoteIpAddress. Configure ASP.NET Core Forwarded Headers Middleware before calling this helper when the application runs behind a proxy. Raw forwarding headers are not read directly because clients can spoof them.

string ip = ClientIPHelper.GetClientIP(httpContext);

IPAddressHelper

Classifies ordinary public Internet IPv4 and IPv6 addresses. Private, loopback, link-local, documentation, reserved, multicast, transition, tunneling, and other special-use addresses return false. IPv4-mapped IPv6 addresses are normalized before classification.

bool publicIPv4 = IPAddressHelper.IsPublicIPAddress("8.8.8.8");       // true
bool privateIPv4 = IPAddressHelper.IsPublicIPAddress("192.168.1.1"); // false
bool loopbackIPv6 = IPAddressHelper.IsPublicIPAddress("::1");        // false

Public HTTP client safety

AddPublicHttpClientSafety registers reusable DNS validation and HTTP connection services for applications that must fetch user-controlled public URLs.

builder.Services.AddPublicHttpClientSafety();

builder.Services.AddHttpClient<MyPublicUrlClient>()
    .ConfigurePrimaryHttpMessageHandler(serviceProvider =>
        serviceProvider.GetRequiredService<PublicHttpMessageHandlerFactory>().Create());

Use IPublicHttpUrlValidator.IsPublicHttpUrlAsync before business processing. The handler performs the authoritative check immediately before connecting and binds the socket to a checked address. It rejects hosts with any non-public DNS result and disables redirects, cookies, and proxy use. Applications must validate every redirect location before issuing the next request.


SmartXFFHeaderExtensions

Middleware extension that configures ForwardedHeaders from appsettings.json.

app.UseSmartXFFHeader();

Configuration (appsettings.json):

{
  "ForwardedHeaders": {
    "HeaderName": "X-Forwarded-For",
    "KnownProxies": [ "203.0.113.1", "203.0.113.2" ]
  }
}
  • HeaderName — custom forwarded-for header name (optional, max 40 chars, must be a valid HTTP header name).
  • KnownProxies — list of trusted proxy IP addresses. When empty or entirely invalid, ASP.NET Core's default loopback-only trusted proxies are retained. A valid explicit list replaces those defaults. Trust behavior does not change automatically in containers.

VersionHelper

Reads version information from the entry assembly.

Member Description
AppVersionBasic File version (AssemblyFileVersionAttribute), or "N/A".
AppVersion Informational version with git hash shortened to 6 chars, e.g. 1.0.0 (ab12cd).
IsNonStableVersion() true if AppVersion contains preview, beta, rc, debug, alpha, test, canary, or nightly.
TryGetFullOSVersion() Full OS version string. On Windows, includes the UBR from the registry, e.g. Microsoft Windows 11 Pro 10.0.22631.4317.
string version = VersionHelper.AppVersion;
bool isPreview = VersionHelper.IsNonStableVersion();
string os = VersionHelper.TryGetFullOSVersion();

EnvironmentHelper

Runtime environment detection and tag parsing.

bool onAzure  = EnvironmentHelper.IsRunningOnAzureAppService(); // checks WEBSITE_SITE_NAME
bool inDocker = EnvironmentHelper.IsRunningInDocker();          // checks DOTNET_RUNNING_IN_CONTAINER

// Reads comma-separated tags from APP_TAGS (or a custom env var)
// Valid characters: a-z A-Z 0-9 - # @ $ ( ) [ ] /
IEnumerable<string> tags = EnvironmentHelper.GetEnvironmentTags();
IEnumerable<string> tags = EnvironmentHelper.GetEnvironmentTags("CUSTOM_TAGS");

SecurityHelper

URL sanitization and password hashing utilities.

Sanitizes links by allowing local absolute paths and HTTP/HTTPS links. Literal IP hosts must be ordinary public Internet addresses. This method does not resolve DNS names and is not a replacement for the public HTTP client safety services when the server makes an outbound request.

string safe = SecurityHelper.SterilizeLink(rawUrl);
HashPassword / GenerateSalt

PBKDF2 password hashing via Microsoft.AspNetCore.Cryptography.KeyDerivation.

string salt = SecurityHelper.GenerateSalt();           // 16 random bytes, Base64
string hash = SecurityHelper.HashPassword(password, salt);

Parameters for HashPassword: prf (default HMACSHA256), iterationCount (default 100000), numBytesRequested (default 32).


UrlExtension

Extension methods on string and Uri.

// Validate URL scheme
bool valid  = url.IsValidUrl();                        // HTTP or HTTPS
bool secure = url.IsValidUrl(UrlScheme.Https);

// Combine base URL with a path segment
string full = "https://example.com".CombineUrl("api/v1");
// → "https://example.com/api/v1"

// Detect localhost
bool local = new Uri("http://localhost:5000").IsLocalhostUrl();

DomainDataHelper

Typed wrapper around AppDomain.CurrentDomain data storage.

DomainDataHelper.SetAppDomainData("MyKey", myValue);
string value = DomainDataHelper.GetAppDomainData<string>("MyKey", defaultValue: "fallback");

ProblemDetailsResultFilter

MVC result filter that converts any non-ProblemDetails 4xx/5xx ObjectResult into RFC 7807/9457 Problem Details format, including a traceId extension.

builder.Services.AddControllers(options =>
{
    options.Filters.Add<ProblemDetailsResultFilter>();
});

Controllers can continue returning semantic helpers and still produce consistent error responses:

return NotFound("Resource not found.");  // → ProblemDetails with status 404

ProblemDetailsStatusCodePages

A StatusCodePages handler that writes RFC 7807 Problem Details for responses with no body (e.g. 404 from middleware).

app.UseStatusCodePages(ProblemDetailsStatusCodePages.Handler);

License

MIT

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.
  • net10.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Edi.AspNetCore.Utils:

Repository Stars
EdiWang/Moonglade
Blog system of https://edi.wang
Version Downloads Last Updated
2.0.0 100 8/15/2026
1.8.0 700 4/7/2026
1.7.0 418 2/23/2026
1.6.0 228 2/10/2026
1.5.0 208 1/23/2026
1.4.1 163 1/18/2026
1.4.0 242 12/21/2025
1.3.0 445 11/13/2025
1.2.0 350 9/28/2025
1.1.0 246 9/20/2025
1.0.0 345 9/19/2025