不做码农 973c3281b2 Squashed commit of the following:
commit 1daa137d98a3a814e3617606b14c737dbb611f4f
Author: 不做码农 <599854767@qq.com>
Date:   Sat Apr 9 14:51:29 2022 +0800

    IPRatelimit添加白名单接口

commit d05690654b889ae3ab8f4add1b76a5859e1ab89a
Author: 不做码农 <599854767@qq.com>
Date:   Fri Apr 8 20:20:11 2022 +0800

    添加页签openPage支持传递参数

commit 861710079a26294c64d70eeadb7630bf83e3bfc4
Author: 不做码农 <599854767@qq.com>
Date:   Fri Apr 8 12:44:28 2022 +0800

    update FileHelper.cs

commit a0cf47c099533fabaf5bd389cf498f08eead2ef4
Author: 不做码农 <599854767@qq.com>
Date:   Thu Apr 7 13:30:47 2022 +0800

    优化代码生成模板

commit 5b376614d02c2d27b6e90252c2a3169adfb0e612
Author: 不做码农 <599854767@qq.com>
Date:   Thu Apr 7 13:30:13 2022 +0800

    IP限制增加百名单接口

commit 939ec56d1db4cad52f7b64555e16d52b5b061360
Author: 不做码农 <599854767@qq.com>
Date:   Mon Apr 4 21:48:27 2022 +0800

    fix 基础sql脚本bug

commit 19c738b974e14b62929dc69c2c6ac1e8540aad98
Author: 不做码农 <599854767@qq.com>
Date:   Mon Apr 4 18:53:02 2022 +0800

    新增加IPRateLimit限制

commit 6b0e6b11b3fdbb5ab53606cf4d0910ae30886365
Author: 不做码农 <599854767@qq.com>
Date:   Mon Apr 4 12:09:39 2022 +0800

    格式化代码

commit 1024471c64beef683b257b38d4904ab7cd509c82
Author: 不做码农 <599854767@qq.com>
Date:   Mon Apr 4 12:02:32 2022 +0800

    自定义异常新增获取LogAttribute属性
2022-04-09 15:06:45 +08:00

28 lines
1.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using AspNetCoreRateLimit;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
namespace ZR.Admin.WebApi.Extensions
{
public static class IPRateExtension
{
public static void AddIPRate(this IServiceCollection services, IConfiguration configuration)
{
if (services == null) throw new ArgumentNullException(nameof(services));
//从appsettings.json中加载常规配置IpRateLimiting与配置文件中节点对应
services.Configure<IpRateLimitOptions>(configuration.GetSection("IpRateLimiting"));
//从appsettings.json中加载Ip规则
services.Configure<IpRateLimitPolicies>(configuration.GetSection("IpRateLimitPolicies"));
//注入计数器和规则存储
services.AddSingleton<IIpPolicyStore, MemoryCacheIpPolicyStore>();
services.AddSingleton<IRateLimitCounterStore, MemoryCacheRateLimitCounterStore>();
//配置(解析器、计数器密钥生成器)
services.AddSingleton<IRateLimitConfiguration, RateLimitConfiguration>();
services.AddSingleton<IProcessingStrategy, AsyncKeyLockProcessingStrategy>();
}
}
}