A simple Native AOT compatible C# library for client side geo blocking in dotnet applications.
- IpGeoBlocker (Ip-based region blocking using the IP-API API)
dotnet add package Piorum.GeoBlocker
using GeoBlocker;
try
{
using IpGeoBlocker gb = IpGeoBlocker.CaliforniaGB();
await gb.EnforceAsync();
}
catch (RegionBlockedException ex)
{
Console.WriteLine(ex.Message);
System.Environment.Exit(0);
}using GeoBlocker;
try
{
using IpGeoBlocker gb = new(["US,CA","US,CO"], IpGeoBlocker.IpApiFormat.CSV, "countryCode,region", throwOnApiFailure: true);
await gb.EnforceAsync();
}
catch (RegionBlockedException ex)
{
Console.WriteLine(ex.Message);
System.Environment.Exit(0);
}
catch (HttpRequestException)
{
Console.WriteLine("API request for geolocation failed, application cannot run");
System.Environment.Exit(0);
}For more information on formats and fields for the ip based geo blocker please see the IP-API Documentation
This library is not affiliated with IP-API, any usage of the IP-API API is subject to IP-API API ToS