public void OnPreRequestHandlerExecute(object sender, EventArgs e) { try { //配置为0:表示关闭软防 if (_freqCount.Trim() == "0") { return; } var application = sender as HttpApplication; var request = new HttpRequestWrapper(application.Context.Request); var response = application.Context.Response; //获取访问的【Controller】和【Action】名 this.GetControllerAndAction(request, out string controllerName, out string actionName); //判断是否需要预防该接口 bool needDefend = DefendAttackContainer.DefendLimitAttackList.Where(x => x.Controller == controllerName && x.Action == actionName) .Any(); //如果不需要防御,那么就返回不处理 if (!needDefend) { return; } //检测是否是攻击的请求 bool hasLimitAttack = this.CheckHasLimitAttack(request, controllerName, actionName); if (hasLimitAttack) { //关闭输出 request.Abort(); response.Close(); } } catch (Exception) { } }