diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/MvcRemoteTenantStore.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/MvcRemoteTenantStore.cs index ed4739c93c..aeb94bc533 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/MvcRemoteTenantStore.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/MvcRemoteTenantStore.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; using Pages.Abp.MultiTenancy.ClientProxies; using Volo.Abp.Caching; @@ -13,6 +15,8 @@ namespace Volo.Abp.AspNetCore.Mvc.Client; public class MvcRemoteTenantStore : ITenantStore, ITransientDependency { + public ILogger Logger { get; set; } + protected AbpTenantClientProxy TenantAppService { get; } protected IHttpContextAccessor HttpContextAccessor { get; } protected IDistributedCache Cache { get; } @@ -24,6 +28,8 @@ public class MvcRemoteTenantStore : ITenantStore, ITransientDependency IDistributedCache cache, IOptions options) { + Logger = NullLogger.Instance; + TenantAppService = tenantAppService; HttpContextAccessor = httpContextAccessor; Cache = cache; @@ -45,6 +51,11 @@ public class MvcRemoteTenantStore : ITenantStore, ITransientDependency { var tenant = await TenantAppService.FindTenantByNameAsync(normalizedName); tenantConfiguration = await Cache.GetAsync(cacheKey); + if (tenant.Success && tenantConfiguration?.Value == null) + { + Logger.LogWarning($"Tenant with name '{normalizedName}' was found, but not present in the distributed cache, " + + "Ensure all applications use the same distributed cache and the same cache key prefix"); + } } if (httpContext != null) @@ -68,8 +79,13 @@ public class MvcRemoteTenantStore : ITenantStore, ITransientDependency var tenantConfiguration = await Cache.GetAsync(cacheKey); if (tenantConfiguration?.Value == null) { - await TenantAppService.FindTenantByIdAsync(id); + var tenant = await TenantAppService.FindTenantByIdAsync(id); tenantConfiguration = await Cache.GetAsync(cacheKey); + if (tenant.Success && tenantConfiguration?.Value == null) + { + Logger.LogWarning($"Tenant with ID '{id}' was found, but not present in the distributed cache, " + + "Ensure all applications use the same distributed cache and the same cache key prefix"); + } } if (httpContext != null) @@ -98,8 +114,13 @@ public class MvcRemoteTenantStore : ITenantStore, ITransientDependency var tenantConfiguration = Cache.Get(cacheKey); if (tenantConfiguration?.Value == null) { - AsyncHelper.RunSync(async () => await TenantAppService.FindTenantByNameAsync(normalizedName)); + var tenant = AsyncHelper.RunSync(async () => await TenantAppService.FindTenantByNameAsync(normalizedName)); tenantConfiguration = Cache.Get(cacheKey); + if (tenant.Success && tenantConfiguration?.Value == null) + { + Logger.LogWarning($"Tenant with name '{normalizedName}' was found, but not present in the distributed cache, " + + "Ensure all applications use the same distributed cache and the same cache key prefix"); + } } if (httpContext != null) @@ -123,8 +144,13 @@ public class MvcRemoteTenantStore : ITenantStore, ITransientDependency var tenantConfiguration = Cache.Get(cacheKey); if (tenantConfiguration?.Value == null) { - AsyncHelper.RunSync(async () => await TenantAppService.FindTenantByIdAsync(id)); + var tenant = AsyncHelper.RunSync(async () => await TenantAppService.FindTenantByIdAsync(id)); tenantConfiguration = Cache.Get(cacheKey); + if (tenant.Success && tenantConfiguration?.Value == null) + { + Logger.LogWarning($"Tenant with ID '{id}' was found, but not present in the distributed cache, " + + "Ensure all applications use the same distributed cache and the same cache key prefix"); + } } if (httpContext != null) diff --git a/framework/src/Volo.Abp.Security/Volo/Abp/Security/Claims/RemoteDynamicClaimsPrincipalContributorCacheBase.cs b/framework/src/Volo.Abp.Security/Volo/Abp/Security/Claims/RemoteDynamicClaimsPrincipalContributorCacheBase.cs index 331a3c7bdf..71fdbf0c17 100644 --- a/framework/src/Volo.Abp.Security/Volo/Abp/Security/Claims/RemoteDynamicClaimsPrincipalContributorCacheBase.cs +++ b/framework/src/Volo.Abp.Security/Volo/Abp/Security/Claims/RemoteDynamicClaimsPrincipalContributorCacheBase.cs @@ -42,7 +42,8 @@ public abstract class RemoteDynamicClaimsPrincipalContributorCacheBase