Esempio n. 1
0
        public async Task Invoke(HttpContext context)
        {
            if (!context.Items.ContainsKey(TenantConstants.TenantInfoContextKey))
            {
                ITenantInfo tenantInfo = null;

                var hostString = context.Request.Host;

                string host = null;

                if (hostString.HasValue)
                {
                    host = hostString.Host;

                    tenantInfo = _tenantDataProvider.LookupTenantByHost(host);
                }

                if (tenantInfo == null)
                {
                    // we could not find any tenant

                    // check if we have a health check running here

                    var healthCheckPort = _tenantDataProvider.HealthCheckPort;

                    if (healthCheckPort != null &&
                        context.Request.Host.Port == healthCheckPort)
                    {
                        var healthCheckTenantHost = _tenantDataProvider.HealthCheckTenantHost;

                        if (!string.IsNullOrEmpty(healthCheckTenantHost))
                        {
                            tenantInfo = _tenantDataProvider.LookupTenantByHost(healthCheckTenantHost);
                        }
                    }

                    if (tenantInfo == null)
                    {
                        _logger.LogError($"No tenant found for host {hostString}");

                        throw new NotFoundApiException(NotFoundApiException.TenantNotFound, $"The tenant for host {host} was not found", host);
                    }
                }

                context.Items.Add(TenantConstants.TenantInfoContextKey, tenantInfo);
            }

            await _next.Invoke(context).ConfigureAwait(false);
        }
Esempio n. 2
0
        public async Task Invoke(HttpContext context)
        {
            if (!context.Items.ContainsKey(TenantConstants.TenantInfoContextKey))
            {
                ITenantInfo tenantInfo = null;

                var hostString = context.Request.Host;

                string host = null;

                if (hostString.HasValue)
                {
                    host = hostString.Host;

                    tenantInfo = _tenantDataProvider.LookupTenantByHost(host);
                }

                if (tenantInfo == null)
                {
                    // we could not find any tenant

                    _logger.LogError($"No tenant found for host {hostString}");

                    throw new NotFoundApiException(NotFoundApiException.TenantNotFound, $"The tenant for host {host} was not found", host);
                }

                context.Items.Add(TenantConstants.TenantInfoContextKey, tenantInfo);
            }

            await _next.Invoke(context).ConfigureAwait(false);
        }