Soenneker.Extensions.HttpContext 4.0.726

Prefix Reserved
There is a newer version of this package available.
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
                    
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="Soenneker.Extensions.HttpContext" Version="4.0.726" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Extensions.HttpContext" Version="4.0.726" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Extensions.HttpContext" />
                    
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 Soenneker.Extensions.HttpContext --version 4.0.726
                    
#r "nuget: Soenneker.Extensions.HttpContext, 4.0.726"
                    
#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 Soenneker.Extensions.HttpContext@4.0.726
                    
#: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=Soenneker.Extensions.HttpContext&version=4.0.726
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Extensions.HttpContext&version=4.0.726
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

alternate text is missing from this package README image 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:

  1. A valid IP address in CF-Connecting-IP.
  2. The first address in X-Forwarded-For, when it is a valid IP address.
  3. 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 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 (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
Loading failed

Update dependency Soenneker.Extensions.String to 4.0.729 (#1159)