- ABP Framework version: v8.1.1
- UI Type: MVC
- Database System: EF Core
- Module project (Separated Deployment & Databases Scenario): yes
Hello, After we upgraded ABP v8.1.1, we got "Tenant not found! There is no tenant with the tenant id or name: a3e378cf-c315-7b7e-da30-3a12881a6c2a" exception while trying to login the application via Web.Host project. We've been using the application without redis so we've disabled it.
"Redis": {
"IsEnabled": "false",
"Configuration": "127.0.0.1"
},
When we enable the redis, there is no problem. We are able to login. So I've decided creating a new module project on abp suite to test the same thing.
- Create a module project on abp suite
- Update the databases to create the tables
- Disable the redis on appsettings.json
- I've changed the TestApplicationNet8SampleIdentityDataSeeder on AuthServer project to seed the users when the tenant is created
- Create a tenant
- Login with this tenant and get the exception
7 Answer(s)
-
0
hi
Create a module project on abp suite
Can you share this project via https://wetransfer.com/
liming.ma@volosoft.com
Thanks
-
0
I've sent it
-
0
-
0
I am running AuthServer, HttpApi.Host and Web.Host
-
0
hi
I confirmed. You have to use Redis in tiered projects. otherwise, you may get some strange problems.
but you can try the code below:
host/TestApplicationNet8.Web.Host/MyMvcRemoteTenantStore.cs
using System; using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Options; using Pages.Abp.MultiTenancy.ClientProxies; using Volo.Abp.AspNetCore.Mvc.Client; using Volo.Abp.Caching; using Volo.Abp.DependencyInjection; using Volo.Abp.MultiTenancy; using Volo.Abp.Threading; namespace TestApplicationNet8; [ExposeServices(typeof(ITenantStore))] public class MyMvcRemoteTenantStore : ITenantStore, ITransientDependency { protected AbpTenantClientProxy TenantAppService { get; } protected IHttpContextAccessor HttpContextAccessor { get; } protected IDistributedCache<TenantConfigurationCacheItem> Cache { get; } protected AbpAspNetCoreMvcClientCacheOptions Options { get; } public MyMvcRemoteTenantStore( AbpTenantClientProxy tenantAppService, IHttpContextAccessor httpContextAccessor, IDistributedCache<TenantConfigurationCacheItem> cache, IOptions<AbpAspNetCoreMvcClientCacheOptions> options) { TenantAppService = tenantAppService; HttpContextAccessor = httpContextAccessor; Cache = cache; Options = options.Value; } public async Task<TenantConfiguration?> FindAsync(string normalizedName) { var cacheKey = TenantConfigurationCacheItem.CalculateCacheKey(normalizedName); var httpContext = HttpContextAccessor?.HttpContext; if (httpContext != null && httpContext.Items[cacheKey] is TenantConfigurationCacheItem tenantConfigurationInHttpContext) { return tenantConfigurationInHttpContext?.Value; } var tenantConfiguration = await Cache.GetAsync(cacheKey); if (tenantConfiguration?.Value == null) { var tenant = await TenantAppService.FindTenantByNameAsync(normalizedName); if (tenant.Success) { tenantConfiguration = new TenantConfigurationCacheItem(new TenantConfiguration(tenant.TenantId!.Value, tenant.NormalizedName!)); await Cache.SetAsync(cacheKey, tenantConfiguration); } } if (httpContext != null) { httpContext.Items[cacheKey] = tenantConfiguration; } return tenantConfiguration?.Value; } public async Task<TenantConfiguration?> FindAsync(Guid id) { var cacheKey = TenantConfigurationCacheItem.CalculateCacheKey(id); var httpContext = HttpContextAccessor?.HttpContext; if (httpContext != null && httpContext.Items[cacheKey] is TenantConfigurationCacheItem tenantConfigurationInHttpContext) { return tenantConfigurationInHttpContext?.Value; } var tenantConfiguration = await Cache.GetAsync(cacheKey); if (tenantConfiguration?.Value == null) { var tenant = await TenantAppService.FindTenantByIdAsync(id); if (tenant.Success) { tenantConfiguration = new TenantConfigurationCacheItem(new TenantConfiguration(tenant.TenantId!.Value, tenant.NormalizedName!)); await Cache.SetAsync(cacheKey, tenantConfiguration); } } if (httpContext != null) { httpContext.Items[cacheKey] = tenantConfiguration; } return tenantConfiguration?.Value; } public Task<IReadOnlyList<TenantConfiguration>> GetListAsync(bool includeDetails = false) { return Task.FromResult<IReadOnlyList<TenantConfiguration>>(Array.Empty<TenantConfiguration>()); } public TenantConfiguration? Find(string normalizedName) { var cacheKey = TenantConfigurationCacheItem.CalculateCacheKey(normalizedName); var httpContext = HttpContextAccessor?.HttpContext; if (httpContext != null && httpContext.Items[cacheKey] is TenantConfigurationCacheItem tenantConfigurationInHttpContext) { return tenantConfigurationInHttpContext?.Value; } var tenantConfiguration = Cache.Get(cacheKey); if (tenantConfiguration?.Value == null) { var tenant = AsyncHelper.RunSync(async () => await TenantAppService.FindTenantByNameAsync(normalizedName)); if (tenant.Success) { tenantConfiguration = new TenantConfigurationCacheItem(new TenantConfiguration(tenant.TenantId!.Value, tenant.NormalizedName!)); Cache.Set(cacheKey, tenantConfiguration); } } if (httpContext != null) { httpContext.Items[cacheKey] = tenantConfiguration; } return tenantConfiguration?.Value; } public TenantConfiguration? Find(Guid id) { var cacheKey = TenantConfigurationCacheItem.CalculateCacheKey(id); var httpContext = HttpContextAccessor?.HttpContext; if (httpContext != null && httpContext.Items[cacheKey] is TenantConfigurationCacheItem tenantConfigurationInHttpContext) { return tenantConfigurationInHttpContext?.Value; } var tenantConfiguration = Cache.Get(cacheKey); if (tenantConfiguration?.Value == null) { var tenant = AsyncHelper.RunSync(async () => await TenantAppService.FindTenantByIdAsync(id)); if (tenant.Success) { tenantConfiguration = new TenantConfigurationCacheItem(new TenantConfiguration(tenant.TenantId!.Value, tenant.NormalizedName!)); Cache.Set(cacheKey, tenantConfiguration); } } if (httpContext != null) { httpContext.Items[cacheKey] = tenantConfiguration; } return tenantConfiguration?.Value; } }
-
0
It appears that it is a problem with the newest version. We haven't experienced such an issue so far. Btw, I've tried the code above and it works. If I understand correctly, we MUST enable the redis with tiered applications after v8.0, right?
-
0
hi
Yes, You have to enable the Redis.
https://support.abp.io/QA/Questions/6533/Why-do-I-need-the-Redis-cache-for-the-public-website#answer-3a10363f-48d7-73fe-88fc-51114ebe105d