public override void OnActionExecuting(ActionExecutingContext context) { _logger.LogInformation( $"IP: {context.HttpContext.Connection.RemoteIpAddress}"); if (IPHelper.IsTrustIP(context.HttpContext.Connection.RemoteIpAddress)) { base.OnActionExecuting(context); return; } context.Result = new StatusCodeResult(403); }
public async Task Invoke(HttpContext context) { var remoteIp = context.Connection.RemoteIpAddress; _logger.LogInformation( $"IP: {remoteIp}"); if (IPHelper.IsTrustIP(remoteIp)) { await _next.Invoke(context); return; } context.Response.StatusCode = (int)HttpStatusCode.Forbidden; }