using AspNetCoreRateLimit; using EntrustSettle.Common; using Microsoft.AspNetCore.Builder; using NLog; using System; namespace EntrustSettle.Extensions.Middlewares { /// /// ip 限流 /// public static class IpLimitMiddleware { public static void UseIpLimitMiddle(this IApplicationBuilder app) { if (app == null) throw new ArgumentNullException(nameof(app)); try { if (AppSettings.app("Middleware", "IpRateLimit", "Enabled").ObjToBool()) { app.UseIpRateLimiting(); } } catch (Exception e) { LogManager.GetCurrentClassLogger().Error(e, "Error occured limiting ip rate. {ex}", e.Message); throw; } } } }