public static IpGeoBlockOptions GetConfiguration() { var options = new IpGeoBlockOptions(); options.BlockedIpAddresses.Add(BlockedIpAddress); options.GeoLite2Path = "GeoLite2-Country.mmdb"; return options; }
internal static void IpGeoBlock( this IAppBuilder app, IpGeoBlockOptions options, RemoteIdAddressFunc getRemoteIpAddress) { if (app == null) { throw new ArgumentNullException(nameof(app)); } app.Use<IpGeoBlockMiddleware>(options, getRemoteIpAddress); }
internal static void IpGeoBlock( this IAppBuilder app, IpGeoBlockOptions options, RemoteIdAddressFunc getRemoteIpAddress) { if (app == null) { throw new ArgumentNullException(nameof(app)); } app.Use <IpGeoBlockMiddleware>(options, getRemoteIpAddress); }
public IpGeoBlockMiddleware( OwinMiddleware next, IpGeoBlockOptions options, RemoteIdAddressFunc getRemoteIpAddress = null) : base(next) { if (next == null) { throw new ArgumentNullException(nameof(next)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } // Check if MaxMind GeoLite2 database is available if (string.IsNullOrEmpty(options.GeoLite2Path)) { throw new ArgumentNullException(nameof(options.GeoLite2Path)); } if (!File.Exists(options.GeoLite2Path)) { throw new FileNotFoundException($"MaxMind GeoLit2 Country database is not found at {options.GeoLite2Path}. Please download the database from https://dev.maxmind.com/geoip/geoip2/geolite2/."); } // Check that user added only denied countries or only allowed countries if (options.AllowedCountries.Count > 0 && options.BlockedCountries.Count > 0) { throw new InvalidOperationException("You have to choose only allowed contries or only blocked countries."); } _options = options; _ipDbReader = new DatabaseReader(_options.GeoLite2Path); if (getRemoteIpAddress != null) { _getRemoteIpAddress = getRemoteIpAddress; } }
public static void IpGeoBlock(this IAppBuilder app, IpGeoBlockOptions options) { app.IpGeoBlock(options, null); }