Edi.AspNetCore.Utils 1.8.0

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

Extracts the real client IP address from an HttpContext, respecting common proxy and CDN forwarding headers.

Checked headers (in order of preference):

Header Used by
X-Azure-ClientIP Azure Front Door
CF-Connecting-IP Cloudflare
X-Forwarded-For Standard proxy
X-Real-IP Nginx
X-Client-IP Apache
True-Client-IP Akamai / Cloudflare Enterprise
HTTP_X_FORWARDED_FOR IIS
HTTP_CLIENT_IP Alternative

Falls back to RemoteIpAddress when no public IP is found in headers. When a custom forwarded-for header is configured via UseSmartXFFHeader, the connection remote IP is returned directly.

string ip = ClientIPHelper.GetClientIP(httpContext);

SmartXFFHeaderExtensions

Middleware extension that configures ForwardedHeaders from appsettings.json. Automatically skips KnownProxies configuration when running in Docker.

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 (skipped in Docker environments).

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 a URL against open-redirect and SSRF attacks. Returns "#" for invalid, loopback, or private-IP URLs.

string safe = SecurityHelper.SterilizeLink(rawUrl);
IsPrivateIP

Tests whether an IPv4 address belongs to a private/LAN range (10.x, 172.16–31.x, 192.168.x, 127.x).

bool isPrivate = SecurityHelper.IsPrivateIP("192.168.1.1"); // true
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, runs on Microsoft Azure
Version Downloads Last Updated
1.8.0 266 4/7/2026
1.7.0 385 2/23/2026
1.6.0 207 2/10/2026
1.5.0 190 1/23/2026
1.4.1 144 1/18/2026
1.4.0 224 12/21/2025
1.3.0 426 11/13/2025
1.2.0 329 9/28/2025
1.1.0 230 9/20/2025
1.0.0 329 9/19/2025