Soenneker.Extensions.HttpContext
4.0.726
Prefix Reserved
See the version list below for details.
dotnet add package Soenneker.Extensions.HttpContext --version 4.0.726
NuGet\Install-Package Soenneker.Extensions.HttpContext -Version 4.0.726
<PackageReference Include="Soenneker.Extensions.HttpContext" Version="4.0.726" />
<PackageVersion Include="Soenneker.Extensions.HttpContext" Version="4.0.726" />
<PackageReference Include="Soenneker.Extensions.HttpContext" />
paket add Soenneker.Extensions.HttpContext --version 4.0.726
#r "nuget: Soenneker.Extensions.HttpContext, 4.0.726"
#:package Soenneker.Extensions.HttpContext@4.0.726
#addin nuget:?package=Soenneker.Extensions.HttpContext&version=4.0.726
#tool nuget:?package=Soenneker.Extensions.HttpContext&version=4.0.726
Soenneker.Extensions.HttpContext
Small ASP.NET Core helpers for local-request checks, Basic authentication challenges, and proxy-aware client IP lookup.
Installation
dotnet add package Soenneker.Extensions.HttpContext
Identify local requests
using Soenneker.Extensions.HttpContext;
if (httpContext.IsLocalRequest())
{
// Apply behavior intended only for requests from this host.
}
IsLocalRequest() returns true when the remote address is loopback, matches the local connection address, or both addresses are absent. It returns false when only the remote address is absent. It examines the connection addresses after any middleware that may have rewritten them.
Return a Basic authentication challenge
httpContext.SetUnauthorized();
return;
SetUnauthorized() sets status code 401 and adds WWW-Authenticate: Basic unless a challenge header already exists. It does not write a response body or end request processing, so return from the endpoint or middleware after calling it.
Read the client IP
string? clientIp = httpContext.GetRequestIp();
The lookup order is:
- A valid IP address in
CF-Connecting-IP. - The first address in
X-Forwarded-For, when it is a valid IP address. HttpContext.Connection.RemoteIpAddress.
Forwarding headers are supplied by the caller and can be spoofed unless your edge proxy removes incoming copies and writes trusted values. Only use the returned forwarded address for authorization, rate limiting, or auditing when that trust boundary is enforced. In standard ASP.NET Core deployments, prefer configuring Forwarded Headers Middleware and then reading RemoteIpAddress directly when possible.
Malformed or blank forwarding values are ignored. If no usable address is available, GetRequestIp() returns null.
| Product | Versions 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. |
-
net10.0
- Soenneker.Extensions.String (>= 4.0.729)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Soenneker.Extensions.HttpContext:
| Package | Downloads |
|---|---|
|
Soenneker.Swashbuckle.Authentication
A middleware implementing basic authentication and RBAC support for Swashbuckle (Swagger) |
|
|
Soenneker.Hangfire.BasicAuthentication
Protects the Hangfire dashboard with PBKDF2-backed HTTP Basic authentication |
|
|
Soenneker.Extensions.IHttpContextAccessors
A collection of helpful IHttpContextAccessor extension methods |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.727 | 0 | 8/30/2026 |
| 4.0.726 | 42 | 8/30/2026 |
| 4.0.725 | 37 | 8/30/2026 |
| 4.0.724 | 32 | 8/30/2026 |
| 4.0.723 | 46 | 8/29/2026 |
| 4.0.722 | 54 | 8/29/2026 |
| 4.0.721 | 36 | 8/29/2026 |
| 4.0.720 | 84 | 8/29/2026 |
| 4.0.719 | 163 | 8/26/2026 |
| 4.0.718 | 140 | 8/25/2026 |
| 4.0.717 | 256 | 8/21/2026 |
| 4.0.716 | 275 | 8/18/2026 |
| 4.0.715 | 165 | 8/18/2026 |
| 4.0.714 | 214 | 8/12/2026 |
| 4.0.713 | 246 | 8/8/2026 |
| 4.0.712 | 150 | 8/7/2026 |
| 4.0.711 | 200 | 7/29/2026 |
| 4.0.710 | 193 | 7/28/2026 |
| 4.0.709 | 139 | 7/28/2026 |
| 4.0.708 | 140 | 7/28/2026 |
Update dependency Soenneker.Extensions.String to 4.0.729 (#1159)