刘磊
2025-04-19 bd02cb3fa0fa75ffafb2cf17501929b1b1e0029b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
 
using Microsoft.AspNetCore.Builder;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Core.Helper;
 
namespace WIDESEAWCS_Core.Middlewares
{
    /// <summary>
    /// ip 限流
    /// </summary>
    public static class IpLimitMiddleware
    {
        /// <summary>
        /// ip限流
        /// </summary>
        /// <param name="app"></param>
        /// <exception cref="ArgumentNullException"></exception>
        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)
            //{
            //    Log.Error($"Error occured limiting ip rate.\n{e.Message}");
            //    throw;
            //}
        }
    }
}