mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 16:13:26 +08:00
【新增】新增客户端IP限流模块。
This commit is contained in:
@@ -4,6 +4,10 @@
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AspNetCoreRateLimit" Version="4.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CoreCms.Net.Auth\CoreCms.Net.Auth.csproj" />
|
||||
<ProjectReference Include="..\CoreCms.Net.Configuration\CoreCms.Net.Configuration.csproj" />
|
||||
|
||||
38
CoreCms.Net.Middlewares/IpLimitMiddleware.cs
Normal file
38
CoreCms.Net.Middlewares/IpLimitMiddleware.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user