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.

33 lines
860 B
C#

using AspNetCoreRateLimit;
using EntrustSettle.Common;
using Microsoft.AspNetCore.Builder;
using NLog;
using System;
namespace EntrustSettle.Extensions.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 (AppSettings.app("Middleware", "IpRateLimit", "Enabled").ObjToBool())
{
app.UseIpRateLimiting();
}
}
catch (Exception e)
{
LogManager.GetCurrentClassLogger().Error(e, "Error occured limiting ip rate. {ex}", e.Message);
throw;
}
}
}
}