From 7417e5cef48e5389000b5bdcd95a4784b9c704bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sun, 22 Jan 2017 22:30:49 +0300 Subject: [PATCH] Log tenantid header values if more than one provided. --- .../AspNetCore/MultiTenancy/HeaderTenantResolver.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/HeaderTenantResolver.cs b/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/HeaderTenantResolver.cs index 4f71e83102..5b6ffe6f05 100644 --- a/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/HeaderTenantResolver.cs +++ b/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/HeaderTenantResolver.cs @@ -1,5 +1,7 @@ using System.Linq; using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; using Volo.Abp.MultiTenancy; using Volo.ExtensionMethods.Collections.Generic; @@ -9,13 +11,14 @@ namespace Volo.Abp.AspNetCore.MultiTenancy { protected override string GetTenantIdOrNameFromHttpContextOrNull(ITenantResolveContext context, HttpContext httpContext) { - //TODO: Get first one if provided multiple values and write a log if (httpContext.Request.Headers.IsNullOrEmpty()) { return null; } - var tenantIdHeader = httpContext.Request.Headers[context.GetAspNetCoreMultiTenancyOptions().TenantIdKey]; + var tenantIdKey = context.GetAspNetCoreMultiTenancyOptions().TenantIdKey; + + var tenantIdHeader = httpContext.Request.Headers[tenantIdKey]; if (tenantIdHeader == string.Empty || tenantIdHeader.Count < 1) { return null; @@ -23,7 +26,9 @@ namespace Volo.Abp.AspNetCore.MultiTenancy if (tenantIdHeader.Count > 1) { - + context.ServiceProvider.GetRequiredService>().LogWarning( + $"HTTP request includes more than one {tenantIdKey} header value. First one will be used. All of them: {tenantIdHeader.JoinAsString(", ")}" + ); } return tenantIdHeader.First();