Пример #1
0
        /// <summary>
        /// 実際にIP Addressをチェックする
        /// </summary>
        /// <param name="context"></param>
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            _logger.LogInformation($"Remote IpAddress: {context.HttpContext.Connection.RemoteIpAddress}");

            var remoteIp = context.HttpContext.Connection.RemoteIpAddress;

            _logger.LogDebug($"Request from Remote IP address: {remoteIp}");

            if (_acl.Allow(remoteIp))
            {
                _logger.LogInformation($"Allow Request from Remote IP address: {remoteIp}");
                base.OnActionExecuting(context);
            }
            else
            {
                _logger.LogInformation($"Forbidden Request from Remote IP address: {remoteIp}");
                context.Result = new StatusCodeResult(401);
                return;
            }
        }