using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using AspNetCoreRateLimit; using CoreCms.Net.Configuration; using CoreCms.Net.Loging; using Hangfire.Logging; using Microsoft.AspNetCore.Builder; using NLog; using LogLevel = NLog.LogLevel; namespace CoreCms.Net.Middlewares { /// /// 限制 ip 流量 /// public static class IpLimitMiddleware { public static void UseIpLimitMiddle(this IApplicationBuilder app) { if (app == null) throw new ArgumentNullException(nameof(app)); try { if (AppSettingsConstVars.MiddlewareIpRateLimitEnabled) { app.UseIpRateLimiting(); } } catch (Exception e) { NLogUtil.WriteFileLog(LogLevel.Error, LogType.ApiRequest, "全局捕获异常", "限制ip流量异常", e); throw; } } } }