/// <summary> /// /// </summary> /// <param name="filterContext"></param> public override void OnActionExecuting(ActionExecutingContext filterContext) { string ip = filterContext.HttpContext.Request.UserHostAddress; ThrottleEntry entry = null; if (store.TryGetValue(ip, out entry)) { //请求超过了1分钟 if (entry.RequestStart + TimeSpan < DateTime.UtcNow) { store.Rollover(ip); } } entry = store.IncrementRequests(ip); if (entry.Requests > MaxRequests) { filterContext.Result = new ResponseModel <string>(ErrorCode.requests_has_been_exceeded, ""); return; } }
public bool TryGetValue(string key, out ThrottleEntry entry) { return(throttleStore.TryGetValue(key, out entry)); }