You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
890 B
C#

using AspNetCoreRateLimit;
using Admin.Core.Common;
using log4net;
using Microsoft.AspNetCore.Builder;
using System;
namespace Admin.Core.Extensions
{
/// <summary>
/// ip 限流
/// </summary>
public static class IpLimitMildd
{
private static readonly ILog log = LogManager.GetLogger(typeof(IpLimitMildd));
public static void UseIpLimitMildd(this IApplicationBuilder app)
{
if (app == null) throw new ArgumentNullException(nameof(app));
try
{
if (Appsettings.app("Middleware", "IpRateLimit", "Enabled").ObjToBool())
{
app.UseIpRateLimiting();
}
}
catch (Exception e)
{
log.Error($"Error occured limiting ip rate.\n{e.Message}");
throw;
}
}
}
}