public async Task Invoke(HttpContext context) { if (SioService.GetIpConfig <bool>("IsRetrictIp")) { var ipAddress = (string)context.Connection.RemoteIpAddress?.ToString(); string allowedIps = SioService.GetIpConfig <string>("AllowedIps"); string exceptIps = SioService.GetIpConfig <string>("ExceptIps"); string remoteIp = context.Connection?.RemoteIpAddress?.ToString(); if ( // allow localhost (allowedIps != "*" && !allowedIps.Contains(remoteIp)) || (exceptIps.Contains(remoteIp)) ) { context.Response.StatusCode = 403; return; } } await Next(context); }
/// <summary> /// Called before the action method is invoked. /// </summary> /// <param name="context">The action executing context.</param> public override void OnActionExecuting(ActionExecutingContext context) { GetLanguage(); AlertAsync("Executing request", 200); if (SioService.GetIpConfig<bool>("IsRetrictIp")) { var allowedIps = SioService.GetIpConfig<JArray>("AllowedIps") ?? new JArray(); var exceptIps = SioService.GetIpConfig<JArray>("ExceptIps") ?? new JArray(); string remoteIp = Request.HttpContext?.Connection?.RemoteIpAddress?.ToString(); if ( // allow localhost //remoteIp != "::1" && (!allowedIps.Any(t => t.Value<string>() == "*") && !allowedIps.Contains(remoteIp)) || (exceptIps.Any(t => t.Value<string>() == remoteIp)) ) { _forbidden = true; } } base.OnActionExecuting(context); }