![]() |
VOOZH | about |
dotnet add package mostlylucid.geodetection --version 7.5.5
NuGet\Install-Package mostlylucid.geodetection -Version 7.5.5
<PackageReference Include="mostlylucid.geodetection" Version="7.5.5" />
<PackageVersion Include="mostlylucid.geodetection" Version="7.5.5" />Directory.Packages.props
<PackageReference Include="mostlylucid.geodetection" />Project file
paket add mostlylucid.geodetection --version 7.5.5
#r "nuget: mostlylucid.geodetection, 7.5.5"
#:package mostlylucid.geodetection@7.5.5
#addin nuget:?package=mostlylucid.geodetection&version=7.5.5Install as a Cake Addin
#tool nuget:?package=mostlylucid.geodetection&version=7.5.5Install as a Cake Tool
Geographic location detection and routing middleware for ASP.NET Core applications with multiple provider support.
dotnet add package Mostlylucid.GeoDetection
// Uses free ip-api.com API, no account needed
builder.Services.AddGeoRoutingWithIpApi();
app.UseGeoRouting();
builder.Services.AddGeoRouting(
configureProvider: options =>
{
options.Provider = GeoProvider.MaxMindLocal;
options.AccountId = 123456; // Free account from maxmind.com
options.LicenseKey = "your-license-key";
}
);
app.UseGeoRouting();
builder.Services.AddGeoRoutingSimple();
| 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 |
{
"GeoLite2": {
"Provider": "IpApi",
"AccountId": null,
"LicenseKey": null,
"DatabasePath": "data/GeoLite2-City.mmdb",
"EnableAutoUpdate": true,
"CacheDuration": "01:00:00",
"FallbackToSimple": true
}
}
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);
}
);
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));
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");
[GeoRoute(AllowedCountries = new[] { "US", "CA" })]
public class NorthAmericaController : Controller
{
public IActionResult Index() => View();
}
[GeoRoute(BlockedCountries = new[] { "XX" })]
public IActionResult Restricted() => View();
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
});
}
}
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
}
var stats = geoService.GetStatistics();
// stats.TotalLookups, stats.CacheHits, stats.DatabaseLoaded, etc.
GNU AGPLv3
| 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. |
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. |
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 |
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