public async Task Invoke(HttpContext context) { bool clientBanned = false; string clientId = string.Empty; try { clientId = context.User?.Identity?.Name; if (!string.IsNullOrEmpty(clientId)) { clientBanned = await _clientAccountClient.IsClientBannedAsync(clientId); } } catch (Exception ex) { await _log.WriteErrorAsync(nameof(ClientBansMiddleware), nameof(Invoke), clientId, ex); } finally { if (!clientBanned) { await _next.Invoke(context); } else { context.Response.StatusCode = 403; } } }