mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 18:13:26 +08:00
39 lines
1.0 KiB
C#
39 lines
1.0 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
/// 限制 ip 流量
|
|
/// </summary>
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|