【调整】移除第三方AspNetCoreRateLimit限流组件,使用.net8自带的RateLimiter特性。

This commit is contained in:
jianweie code
2023-11-17 13:36:08 +08:00
parent 4425c53413
commit 9efb2e11a6
11 changed files with 203 additions and 262 deletions

View File

@@ -4,10 +4,6 @@
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AspNetCoreRateLimit" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CoreCms.Net.Auth\CoreCms.Net.Auth.csproj" />
<ProjectReference Include="..\CoreCms.Net.Configuration\CoreCms.Net.Configuration.csproj" />

View File

@@ -1,39 +0,0 @@
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;
}
}
}
}