VOOZH about

URL: https://www.nuget.org/packages/mostlylucid.geodetection/

⇱ NuGet Gallery | mostlylucid.geodetection 7.5.5




👁 Image
mostlylucid.geodetection 7.5.5

dotnet add package mostlylucid.geodetection --version 7.5.5
 
 
NuGet\Install-Package mostlylucid.geodetection -Version 7.5.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="mostlylucid.geodetection" Version="7.5.5" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="mostlylucid.geodetection" Version="7.5.5" />
 
Directory.Packages.props
<PackageReference Include="mostlylucid.geodetection" />
 
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 mostlylucid.geodetection --version 7.5.5
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: mostlylucid.geodetection, 7.5.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 mostlylucid.geodetection@7.5.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=mostlylucid.geodetection&version=7.5.5
 
Install as a Cake Addin
#tool nuget:?package=mostlylucid.geodetection&version=7.5.5
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Mostlylucid.GeoDetection

Geographic location detection and routing middleware for ASP.NET Core applications with multiple provider support.

Features

  • Multiple Providers: ip-api.com (free, no account), MaxMind GeoLite2 (local database), or simple mock
  • Country-Based Routing: Allow/block by country code with middleware and attributes
  • Memory Caching: Fast in-memory caching enabled by default
  • Optional Database Caching: SQLite/EF Core persistent cache (opt-in)
  • Auto-Updates: Automatic MaxMind database downloads and updates

Installation

dotnet add package Mostlylucid.GeoDetection

Quick Start

Option 1: ip-api.com (Easiest - No Setup Required)

// Uses free ip-api.com API, no account needed
builder.Services.AddGeoRoutingWithIpApi();

app.UseGeoRouting();

Option 2: MaxMind GeoLite2 (Best for Production)

builder.Services.AddGeoRouting(
 configureProvider: options =>
 {
 options.Provider = GeoProvider.MaxMindLocal;
 options.AccountId = 123456; // Free account from maxmind.com
 options.LicenseKey = "your-license-key";
 }
);

app.UseGeoRouting();

Option 3: Simple Mock (Development/Testing)

builder.Services.AddGeoRoutingSimple();

Providers

Provider Setup Pros Cons
IpApi None Free, no account needed Rate limited (45/min), online only
MaxMindLocal Free account Fast, offline, accurate Requires account, ~60MB database
Simple None No dependencies Mock data only

Getting a MaxMind Account (Free)

  1. Sign up at maxmind.com/en/geolite2/signup
  2. Generate a license key in your account
  3. Configure AccountId and LicenseKey
  4. Database auto-downloads on startup

Configuration

appsettings.json

{
 "GeoLite2": {
 "Provider": "IpApi",
 "AccountId": null,
 "LicenseKey": null,
 "DatabasePath": "data/GeoLite2-City.mmdb",
 "EnableAutoUpdate": true,
 "CacheDuration": "01:00:00",
 "FallbackToSimple": true
 }
}

Provider Options

builder.Services.AddGeoRouting(
 configureRouting: options =>
 {
 options.Enabled = true;
 options.AllowedCountries = new[] { "US", "CA", "GB" };
 options.BlockedCountries = new[] { "XX" };
 options.AddCountryHeader = true; // Adds X-Country header
 options.StoreInContext = true; // Store in HttpContext.Items
 options.EnableTestMode = true; // Allow header override
 },
 configureProvider: options =>
 {
 options.Provider = GeoProvider.IpApi;
 options.CacheDuration = TimeSpan.FromHours(1);
 }
);

Database Caching (Optional)

By default, only memory caching is used. To persist lookups to a database:

// Add SQLite database cache (call BEFORE AddGeoRouting)
builder.Services.AddGeoCacheDatabase("Data Source=data/geocache.db");

builder.Services.AddGeoRouting(
 configureCache: options =>
 {
 options.Enabled = true;
 options.CacheExpiration = TimeSpan.FromDays(30);
 }
);

Use any EF Core provider by configuring DbContext yourself:

builder.Services.AddDbContext<GeoDbContext>(options =>
 options.UseSqlServer(connectionString));

Country-Based Routing

Endpoint Extensions

app.MapGet("/us-only", () => "US Only Content")
 .RequireCountry("US");

app.MapGet("/eu-content", () => "EU Content")
 .RequireCountry("DE", "FR", "IT", "ES", "NL", "BE");

app.MapGet("/blocked", () => "Not for XX")
 .BlockCountries("XX");

MVC Attributes

[GeoRoute(AllowedCountries = new[] { "US", "CA" })]
public class NorthAmericaController : Controller
{
 public IActionResult Index() => View();
}

[GeoRoute(BlockedCountries = new[] { "XX" })]
public IActionResult Restricted() => View();

Access Location Data

public class MyController : Controller
{
 private readonly IGeoLocationService _geoService;

 public MyController(IGeoLocationService geoService)
 {
 _geoService = geoService;
 }

 public async Task<IActionResult> Index()
 {
 var clientIp = HttpContext.Connection.RemoteIpAddress?.ToString();
 var location = await _geoService.GetLocationAsync(clientIp!);

 return Ok(new
 {
 location?.CountryCode,
 location?.CountryName,
 location?.City,
 location?.Latitude,
 location?.Longitude,
 location?.TimeZone,
 location?.IsVpn,
 location?.IsHosting
 });
 }
}

GeoLocation Model

public class GeoLocation
{
 public string CountryCode { get; set; } // "US", "GB", etc.
 public string CountryName { get; set; } // "United States"
 public string? ContinentCode { get; set; } // "NA", "EU", "AS"
 public string? RegionCode { get; set; } // State/region
 public string? City { get; set; }
 public double? Latitude { get; set; }
 public double? Longitude { get; set; }
 public string? TimeZone { get; set; } // "America/New_York"
 public bool IsVpn { get; set; } // Known VPN/proxy
 public bool IsHosting { get; set; } // Datacenter IP
}

Statistics

var stats = geoService.GetStatistics();
// stats.TotalLookups, stats.CacheHits, stats.DatabaseLoaded, etc.

Notes

  • Supports reverse proxies (X-Forwarded-For, CF-Connecting-IP)
  • Country codes follow ISO 3166-1 alpha-2 standard
  • ip-api.com is rate limited to 45 requests/minute (free tier)
  • MaxMind databases update weekly (auto-update enabled by default)
  • Private/reserved IPs return "XX" country code

License

GNU AGPLv3

Links

Product Versions Compatible and additional computed target framework versions.
.NET net10.0 net10.0 is compatible.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows 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 (1)

Showing the top 1 NuGet packages that depend on mostlylucid.geodetection:

Package Downloads
Mostlylucid.GeoDetection.Contributor

GeoDetection contributor for BotDetection - provides geographic location analysis and geo-based bot detection signals including country/region validation and geo-inconsistency detection.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
7.5.5 45 6/16/2026
7.5.3 43 6/16/2026
7.5.2 52 6/16/2026
7.5.1 47 6/16/2026
7.5.0 48 6/16/2026
7.0.1-alpha0 49 6/4/2026
7.0.0 64 6/1/2026
7.0.0-rc0 53 5/31/2026
7.0.0-alpha2 52 5/31/2026
7.0.0-alpha1 54 5/31/2026
7.0.0-alpha0 58 5/31/2026
6.9.0-alpha0 56 5/28/2026
6.8.9 62 5/26/2026
6.8.8 57 5/26/2026
6.8.6 52 5/26/2026
6.8.5 67 5/25/2026
6.8.4 56 5/25/2026
6.8.3 54 5/25/2026
6.8.2 51 5/25/2026
6.7.7 53 5/24/2026
Loading failed

1.0.0
Initial release of Mostlylucid.GeoDetection.

Features:
- IP-based geolocation detection
- Country-based routing middleware
- Region and city detection support
- Endpoint routing with GeoRoute attribute
- Configurable allowed/blocked country lists
- Memory caching for performance
- ASP.NET Core middleware integration
- Dependency injection support via IServiceCollection
- Configurable options via GeoRoutingOptions