Log tenantid header values if more than one provided.

pull/81/head
Halil İbrahim Kalkan 9 years ago
parent 9c12a159ba
commit 7417e5cef4

@ -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<ILogger<HeaderTenantResolver>>().LogWarning(
$"HTTP request includes more than one {tenantIdKey} header value. First one will be used. All of them: {tenantIdHeader.JoinAsString(", ")}"
);
}
return tenantIdHeader.First();

Loading…
Cancel
Save