public override void OnActionExecuting(ActionExecutingContext context) { ValidateRequest(); ViewBag.culture = culture; if (!string.IsNullOrEmpty(culture)) { ViewBag.assetFolder = MixCmsHelper.GetAssetFolder(culture); } domain = string.Format("{0}://{1}", Request.Scheme, Request.Host); if (MixService.GetIpConfig <bool>("IsRetrictIp")) { var allowedIps = MixService.GetIpConfig <JArray>("AllowedIps") ?? new JArray(); var exceptIps = MixService.GetIpConfig <JArray>("ExceptIps") ?? new JArray(); string remoteIp = Request.HttpContext?.Connection?.RemoteIpAddress?.ToString(); if ( // To allow localhost remove below comment //remoteIp != "::1" && allowedIps.Count > 0 && !allowedIps.Any(t => t["text"].Value <string>() == remoteIp) || ( exceptIps.Count > 0 && exceptIps.Any(t => t["text"].Value <string>() == remoteIp) ) ) { forbidden = true; } } }
public async Task Invoke(HttpContext context) { if (MixService.GetIpConfig <bool>("IsRetrictIp")) { var ipAddress = (string)context.Connection.RemoteIpAddress?.ToString(); string allowedIps = MixService.GetIpConfig <string>("AllowedIps"); string exceptIps = MixService.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(); if (MixService.GetIpConfig <bool>("IsRetrictIp")) { var allowedIps = MixService.GetIpConfig <JArray>("AllowedIps") ?? new JArray(); var exceptIps = MixService.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); }
public override void OnActionExecuting(ActionExecutingContext context) { this.GetLanguage(); if (MixService.GetIpConfig <bool>("IsRetrictIp")) { V_0 = new BaseRestApiController <TDbContext, TModel, TView> .u003cu003ec__DisplayClass14_0(); stackVariable7 = MixService.GetIpConfig <JArray>("AllowedIps"); if (stackVariable7 == null) { dummyVar0 = stackVariable7; stackVariable7 = new JArray(); } V_1 = stackVariable7; stackVariable9 = MixService.GetIpConfig <JArray>("ExceptIps"); if (stackVariable9 == null) { dummyVar1 = stackVariable9; stackVariable9 = new JArray(); } V_2 = stackVariable9; stackVariable10 = V_0; stackVariable13 = this.get_Request().get_HttpContext(); if (stackVariable13 != null) { stackVariable14 = stackVariable13.get_Connection(); if (stackVariable14 != null) { stackVariable15 = stackVariable14.get_RemoteIpAddress(); if (stackVariable15 != null) { stackVariable16 = stackVariable15.ToString(); } else { dummyVar4 = stackVariable15; stackVariable16 = null; } } else { dummyVar3 = stackVariable14; stackVariable16 = null; } } else { dummyVar2 = stackVariable13; stackVariable16 = null; } stackVariable10.remoteIp = stackVariable16; stackVariable17 = V_1; stackVariable18 = BaseRestApiController <TDbContext, TModel, TView> .u003cu003ec.u003cu003e9__14_0; if (stackVariable18 == null) { dummyVar5 = stackVariable18; stackVariable18 = new Func <JToken, bool>(BaseRestApiController <TDbContext, TModel, TView> .u003cu003ec.u003cu003e9.u003cOnActionExecutingu003eb__14_0); BaseRestApiController <TDbContext, TModel, TView> .u003cu003ec.u003cu003e9__14_0 = stackVariable18; } if (!stackVariable17.Any <JToken>(stackVariable18) && !V_1.Contains(JToken.op_Implicit(V_0.remoteIp)) || V_2.Any <JToken>(new Func <JToken, bool>(V_0.u003cOnActionExecutingu003eb__1))) { this._forbidden = true; } } this.OnActionExecuting(context); return; }