/// <summary> /// 检测是否是攻击的请求 /// </summary> private static bool CheckHasLimitAttack(HttpRequest request, string routeName) { if (!int.TryParse(_freqCount, out int maxCount)) { //如果没有配置,默认一秒钟最多3次请求 maxCount = 3; } //获取IP地址 string realIP = request.GetRealIP(); //按具体【RouteName】来预防 string defendkey = DefendAttackContainer.AssemblyName + routeName; IEasyCache easyCache = EasyIocContainer.GetInstance <IEasyCache>(); //判别是否存在流量攻击 string key = $"{realIP}:{defendkey}"; bool hasAttack = easyCache.CheckIsOverStep(key, TimeType.秒, maxCount); return(hasAttack); }
public TokenSvc(IEasyCache easyCache) { _easyCache = easyCache; }
public UserTreeSvc(IEasyCache easyCache) { this._easyCache = easyCache; }