I only allow {this.parallelRequestsToController} parallel requests per user. Try again soon.
"; responseBody = System.Text.Encoding.UTF8.GetBytes(bodyText); } public async Task InvokeAsync(HttpContext context, int idUser, string controllerName) { if(controllerNames?.Any(n => controllerName.StartsWith(n)) == false) { await next(context); return; } var userStat = stat.GetOrAdd(idUser, idUser => new()); var count = userStat.AddOrUpdate(controllerName, 0, (k, v) => v); if(count + 1 < parallelRequestsToController) { try { userStat[controllerName]++; await next(context); } finally { userStat[controllerName]--; } } else { context.Response.Clear(); context.Response.StatusCode = (int)System.Net.HttpStatusCode.TooManyRequests; context.Response.Headers.RetryAfter = "1000"; context.Response.Headers.ContentType = "text/html"; await context.Response.BodyWriter.WriteAsync(responseBody); } } }