Ejemplo n.º 1
0
        public async Task Invoke(HttpContext context,
                                 IIPFencingManager iPFencingManager)
        {
            var  ipAddress        = context.Connection.RemoteIpAddress;
            bool isAllowedRequest = iPFencingManager.IsRequestAllowed(ipAddress);

            if (!isAllowedRequest)
            {
                context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
                context.Response.WriteAsync("Current IP Address is blocked.");
                return;
            }
            await _next.Invoke(context);
        }
 /// <summary>
 /// IPFencing controller's constructor
 /// </summary>
 /// <param name="repository"></param>
 /// <param name="membershipManager"></param>
 /// <param name="userManager"></param>
 /// <param name="configuration"></param>
 /// <param name="httpContextAccessor"></param>
 /// <param name="iPFencingManager"></param>
 /// <param name="organizationSettingRepository"></param>
 public IPFencingController(
     IIPFencingRepository repository,
     IMembershipManager membershipManager,
     ApplicationIdentityUserManager userManager,
     IConfiguration configuration,
     IHttpContextAccessor httpContextAccessor,
     IOrganizationSettingRepository organizationSettingRepository,
     IIPFencingManager iPFencingManager) : base(repository, userManager, httpContextAccessor,
                                                membershipManager, configuration)
 {
     _organizationSettingRepository = organizationSettingRepository;
     _iPFencingManager = iPFencingManager;
     _accessor         = httpContextAccessor;
     _iPFencingOptions = configuration.GetSection(IPFencingOptions.IPFencing).Get <IPFencingOptions>();
 }
Ejemplo n.º 3
0
        public async Task Invoke(HttpContext context,
                                 IIPFencingManager iPFencingManager,
                                 ILogger <IPFilter> logger)
        {
            try
            {
                var  ipAddress        = context.Connection.RemoteIpAddress;
                bool isAllowedRequest = iPFencingManager.IsRequestAllowed(ipAddress);

                if (!isAllowedRequest)
                {
                    context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
                    context.Response.WriteAsync("Current IP Address is blocked.");
                    return;
                }
                await _next.Invoke(context);
            }
            catch (Exception ex)
            {
                logger.LogError(ex, ex.Message);
            }
        }