Exemplo n.º 1
0
        /// <summary>
        /// 检测是否是攻击的请求
        /// </summary>
        private bool CheckHasLimitAttack(HttpRequestWrapper request, string controllerName, string actionName)
        {
            if (!int.TryParse(_freqCount, out int maxCount))
            {
                //如果没有配置,默认一秒钟最多3次请求
                maxCount = 3;
            }

            //获取IP地址
            string realIP = request.GetRealIP();

            //按具体【Action】来预防
            string defendkey = DefendAttackContainer.AssemblyName + controllerName + actionName;

            IEasyCache easyCache = EasyIocContainer.GetInstance <IEasyCache>();

            //判别是否存在流量攻击
            string key = $"{realIP}:{defendkey}";

            bool hasAttack = easyCache.CheckIsOverStep(key, TimeType.秒, maxCount);

            return(hasAttack);
        }