public DynamicCorsPolicyMiddleware(
     RequestDelegate next,
     IDynamicCorsPolicyService corsService,
     ICorsPolicyAccessor corsPolicyAccessor)
 {
     if (corsPolicyAccessor == null)
     {
         throw new ArgumentNullException(nameof(corsPolicyAccessor));
     }
     _next       = next ?? throw new ArgumentNullException(nameof(next));
     CorsService = corsService ?? throw new ArgumentNullException(nameof(corsService));
     _policy     = corsPolicyAccessor.GetPolicy(CorsPoliciesEnums.DynamicCorsPolicyName);
 }
        public async Task InvokeAsync(HttpContext context, ICorsPolicyAccessor accessor

                                      )
        {
            var policy = accessor.GetPolicy(_policyName);

            string[] origins = CorsHelper.GetAllowedOrigins(_apiUrl);
            if (origins?.Length > 0)
            {
                var policyOrigins = policy.Origins;
                var newOrigins    = origins.Except(policyOrigins);
                foreach (var origin in newOrigins)
                {
                    policy.Origins.Add(origin);
                }
            }

            await _next(context);
        }
Пример #3
0
 public AddCorsController(ICorsPolicyAccessor corsPolicyAccessor)
 {
     this._corsPolicyAccessor = corsPolicyAccessor;
 }