hi , I'm trying to use the subdomain as Tenant approach. I updated my appconfig to use the https://{TENANCY_NAME}.domain.com/.
When the tenant is already registered, it will locate the tenant login page. If it is not registered, it will locate the host login page. I want to go to the Host login page only when I enter admin.domain.com. Other unregistered tenants are located. 404 page. What should I do?
Thanks in advance!
8 Answer(s)
-
0
hi,
for your subdomain issues you can create your own DomainTenantResolveContributor
-
0
<cite>alper: </cite> hi,
for your subdomain issues you can create your own DomainTenantResolveContributor
public class MyDomainTenantResolveContributor : ITenantResolveContributor, ITransientDependency { private readonly IHttpContextAccessor _httpContextAccessor; private readonly IWebMultiTenancyConfiguration _multiTenancyConfiguration; private readonly ITenantStore _tenantStore; public MyDomainTenantResolveContributor( IHttpContextAccessor httpContextAccessor, IWebMultiTenancyConfiguration multiTenancyConfiguration, ITenantStore tenantStore) { _httpContextAccessor = httpContextAccessor; _multiTenancyConfiguration = multiTenancyConfiguration; _tenantStore = tenantStore; } public int? ResolveTenantId() { if (_multiTenancyConfiguration.DomainFormat.IsNullOrEmpty()) { return null; } var httpContext = _httpContextAccessor.HttpContext; if (httpContext == null) { return null; } var hostName = httpContext.Request.Host.Host.RemovePreFix("http://", "https://").RemovePostFix("/"); var domainFormat = _multiTenancyConfiguration.DomainFormat.RemovePreFix("http://", "https://").Split(':')[0].RemovePostFix("/"); var result = new FormattedStringValueExtracter().Extract(hostName, domainFormat, true, '/'); if (!result.IsMatch || !result.Matches.Any()) { return null; } var tenancyName = result.Matches[0].Value; if (string.Equals(tenancyName, "admin", StringComparison.OrdinalIgnoreCase)) { return null; } var tenantInfo = _tenantStore.Find(tenancyName); if (tenantInfo == null) { throw new UserFriendlyException("404", "404Test"); } return tenantInfo.Id; } }
public override void PreInitialize() { IocManager.Register<ITenantResolveContributor, MyDomainTenantResolveContributor>(DependencyLifeStyle.Transient); }
Like this? But it doesn't seem to be enforced...
-
0
add it to resolvers in the PreInitalize method of your web module
Configuration.MultiTenancy.Resolvers.Insert(0,new MyDomainTenantResolveContributor());
-
0
<cite>maliming: </cite> add it to resolvers in the PreInitalize method of your web module
Configuration.MultiTenancy.Resolvers.Insert(0,new MyDomainTenantResolveContributor());
public override void PreInitialize() { Configuration.MultiTenancy.Resolvers.Insert(0, typeof(MyDomainTenantResolveContributor)); }
It's ready to go, thank you very much
-
0
super!
-
0
@luqc1985 Does switching back to the host (using the "Back to my account" button) from any other tenants works too?
-
0
@michelmk2 I didn't notice , that I just tried it, it is also 404. Back to my account also needs to modify the corresponding link. There is no tenant information in the abp object, only appPath is found.
-
0
Latest problem is related to https://github.com/aspnetzero/aspnet-zero-core/issues/1609.
Please reopen the issue if it doesn't help.