Lam*_*mar 27 c# asp.net algorithm throttling rate-limiting
可能/部分重复:
我正在寻找为Web应用程序实现移动时间窗口速率限制算法的最佳方法,以减少垃圾邮件或暴力攻击.
使用的示例是"在过去5分钟内来自给定IP的最大失败登录尝试次数","最近N分钟内的最大((帖子/投票/等等)...").
我宁愿使用移动时间窗口算法,而不是每X分钟重新统计一次(比如twitter api).
这将是一个C#/ ASP.Net应用程序.
ZZ *_*der 23
我们发现Token Bucket是这种速率限制的更好算法.它广泛用于路由器/交换机,因此我们的操作人员更熟悉这个概念.
只是为这个问题添加一个更"现代"的答案:对于.NET WebAPI,WebApiThrottle非常出色,可能会开箱即用.
它也可以在NuGet上使用.
实施只需一分钟左右,而且可以高度定制:
config.MessageHandlers.Add(new ThrottlingHandler()
{
Policy = new ThrottlePolicy(perSecond: 1, perMinute: 30, perHour: 500, perDay:2000)
{
IpThrottling = true,
ClientThrottling = true,
EndpointThrottling = true
},
Repository = new CacheRepository()
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23062 次 |
| 最近记录: |