Skip to content

Piorum/GeoBlocker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GeoBlocker

A simple Native AOT compatible C# library for client side geo blocking in dotnet applications.

Blockers

  • IpGeoBlocker (Ip-based region blocking using the IP-API API)

Example Usage

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

Disclaimer

This library is not affiliated with IP-API, any usage of the IP-API API is subject to IP-API API ToS

About

No description, website, or topics provided.

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors

Languages