private void OnEnter(object sender, EventArgs e) { var context = ((HttpApplication)sender).Context; if (context.Error != null || context.CurrentHandler == null || context.CurrentHandler is DefaultHttpHandler) { return; } var cache = new WebCache(context.Cache); var request = context.Request; foreach (var ip in request.UserHosts()) { var key = KeyPrefix + ip; if (cache.Increment(key, ThrottlePeriod) >= RateQuota) { if (NoExceptionPathRegex == null || !NoExceptionPathRegex.IsMatch(request.RawUrl)) { throw new LimitExceededException(string.Format(CultureInfo.InvariantCulture, "The maximum quota for incoming requests ({0} queries per {1}) has been exceeded.", RateQuota, TimeSpanHelper.ToLongTimeString(ThrottlePeriod).ToLowerInvariant())); } } } }