AspNetCoreVisitorInfo 1.0.5

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

AspNetCoreVisitorInfo

HttpContext extension methods that read the visitor's IP, country, and city from the proxy/CDN headers that Cloudflare, CloudFront, App Engine, Azure, and common reverse proxies set.

Examples

string ipAddress = httpContext.GetVisitorIp();
string country = httpContext.GetVisitorCountry();
string city = httpContext.GetVisitorCity();

Each method walks an ordered list of headers, most specific first, and returns the first usable value. GetVisitorIp() falls back to HttpContext.Connection.RemoteIpAddress; all three return an empty string when nothing matches.

Method Headers checked, in order
GetVisitorIp CF-Connecting-IP, X-Forwarded-For, Forwarded, X-Real-IP, X-Client-IP, X-Cluster-Client-IP, True-Client-IP, CloudFront-Viewer-Address, X-Original-Forwarded-For
GetVisitorCountry CF-IPCountry, CloudFront-Viewer-Country, X-AppEngine-Country, X-Country-Code, X-GeoIP-Country, X-Real-Country, X-Forwarded-Country, X-Azure-ClientIP-Country
GetVisitorCity CF-IPCity, CloudFront-Viewer-City, X-AppEngine-City, X-City-Name

GetVisitorIp() returns a single parsed address: the left-most entry of an X-Forwarded-For list, the for= parameter of an RFC 7239 Forwarded header, and the address without the port from CloudFront-Viewer-Address. A header that is absent, empty, or not a valid IP address is skipped and the next header in the chain is used.

Security: these headers are not trustworthy by default

Every value returned by these methods comes from a request header the caller controls. Anyone who can reach your application can send CF-Connecting-IP: 1.2.3.4 or CF-IPCountry: US and this library will return it — it has no way to know which proxy, if any, is actually in front of you.

These values are safe to trust only if both of the following hold:

  1. Your application is not reachable directly — every request arrives through a proxy you control.
  2. That proxy overwrites the header on ingress rather than appending to a client-supplied value.

If you cannot say yes to both, do not use these values for authorization, rate limiting, ban lists, audit logs, fraud checks, or geo-gating. Use HttpContext.Connection.RemoteIpAddress, configured with ASP.NET Core's ForwardedHeadersMiddleware and its KnownProxies / KnownNetworks allow-list, which validates the peer before honouring a header. Analytics and other non-security uses are what this library is for.

Narrowing the chain

The default chain is ordered by convention, not by trust: it tries CF-Connecting-IP first whether or not you are behind Cloudflare. If you know which header your proxy sets, pass it explicitly so the others cannot be used to spoof the value:

// Behind Cloudflare: trust only the header Cloudflare overwrites, ignore everything else.
string ipAddress = httpContext.GetVisitorIp("CF-Connecting-IP");
string country = httpContext.GetVisitorCountry("CF-IPCountry");

Passing an empty array skips the headers entirely and uses the connection's remote IP address.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  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.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.5 115 9/15/2026
1.0.4 647 6/18/2025
1.0.3 246 6/18/2025
1.0.2 248 6/18/2025
1.0.1 246 6/18/2025
1.0.0 246 6/18/2025