Base solution for your next web application
Open Closed

RE: Angualr2 Tenant Subdomain #2646


User avatar
0
paradoxit created

I'm having a number of issues with tenant sub-domains in the previous Angular2 release.

Here is my appconfig.json

{
    "remoteServiceBaseUrl": "https://{TENANCY_NAME}.myapidomain.co.uk",
    "appBaseUrl": "https://{TENANCY_NAME}.mydomain.co.uk"
}

Issue 1

  • When I click logout I get redirected to <a class="postlink" href="https://null.mydomain.co.uk">https://null.mydomain.co.uk</a> Can you please advise where the code is that determines this URL so I can fix it.

Issue 2

  • Tenant detection is not working in WebUrlService (ExtractTenancyNameFromUrl). I can manually return a tenant name and this works for each tenant.

My appsettings.json has

"WebSiteRootAddress": "https://{TENANCY_NAME}.mydomain.co.uk/"

Any help or advice on resolving this will be much appreciated.

Kind regards,

David Hawkins


4 Answer(s)
  • User Avatar
    0
    cangunaydin created

    Hello David, I was having the same issue. To fix the first issue. you need to change code in your AppPreBootstrap.ts in your angular app.

    private static getApplicationConfig(callback: () => void) {
            return abp.ajax({
                url: '/assets/appconfig.json',
                method: 'GET',
                headers: {
                    'Abp.TenantId': abp.multiTenancy.getTenantIdCookie()
                }
            }).done(result => {
    
                let subdomainTenancyNameFinder = new SubdomainTenancyNameFinder();
                var tenancyName = subdomainTenancyNameFinder.getCurrentTenancyNameOrNull(result.appBaseUrl);
    
                AppConsts.appBaseUrlFormat = result.appBaseUrl;
                AppConsts.remoteServiceBaseUrlFormat = result.remoteServiceBaseUrl;
    
                if (tenancyName == null) {
                    AppConsts.appBaseUrl = result.appBaseUrl.replace(AppConsts.tenancyNamePlaceHolderInUrl + ".", "");
                    AppConsts.remoteServiceBaseUrl = result.remoteServiceBaseUrl.replace(AppConsts.tenancyNamePlaceHolderInUrl + ".", "");
                } else {
                    AppConsts.appBaseUrl = result.appBaseUrl.replace(AppConsts.tenancyNamePlaceHolderInUrl, tenancyName);
                    AppConsts.remoteServiceBaseUrl = result.remoteServiceBaseUrl.replace(AppConsts.tenancyNamePlaceHolderInUrl, tenancyName);
                }
    
                callback();
            });
        }
    

    It should be fine when you change this part of AppPreBootstrap.ts

    for the second issue. I didn't know very well about it but if you are using abp v1.4 i suggest you to upgrade it to abp v1.5 cause they have fixed couple of problems in the new release related with tenancy resolver. Good luck with it. Best

  • User Avatar
    0
    paradoxit created

    cangunaydin that worked for the logout null issue thanks! :)

  • User Avatar
    0
    michaelhilgers created

    Hi,

    I'm using Abp 1.5.0 with angular2 and Asp.net core. My appconfig.json looks like: { "remoteServiceBaseUrl": "https://pm-host.mydomain.com", "appBaseUrl": "https://pm-{TENANCY_NAME}.mydomain.com" }

    My appsettings.json looks like :

    "App":{ "WebSiteRootAddress": "https://pm-{TENANCY_NAME}.mydomain.com/", "CorsOrigins": "https://pm-tenant1.mydomain.com,https://pm-tenant2.mydomain.com }

    I changed the AppPreBootstrap function to avoid the <a class="postlink" href="https://pm-null.mydomain.com">https://pm-null.mydomain.com</a> as follow

    let subdomainTenancyNameFinder = new SubdomainTenancyNameFinder();
                console.log('1. appBaseUrl : ' + result.appBaseUrl);
                var tenancyName = subdomainTenancyNameFinder.getCurrentTenancyNameOrNull(result.appBaseUrl);
                console.log('2. tenancyName : ' + tenancyName);
                AppConsts.remoteServiceBaseUrl = result.remoteServiceBaseUrl.replace(AppConsts.tenancyNamePlaceHolderInUrl, tenancyName);
    
                AppConsts.appBaseUrlFormat = result.appBaseUrl;
                AppConsts.remoteServiceBaseUrlFormat = result.remoteServiceBaseUrl;
    
                if (tenancyName == null) {
                    AppConsts.appBaseUrl = result.appBaseUrl.replace('-' + AppConsts.tenancyNamePlaceHolderInUrl, "");
                } else {
                    AppConsts.appBaseUrl = result.appBaseUrl.replace(AppConsts.tenancyNamePlaceHolderInUrl, tenancyName);
                }
    

    To show the tenancy name I wrote the consol.log in the preBootstrap function and I could see that the tenancy name was correct but the application didn't change the tenant.

    I'm always logged in as host tenant.

    Any suggestions ?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Thanks a lot @cangunaydin :). As I remember we also fixed it in AspNet Zero but @ParadoxIT and @MichaelHilgers don't have latest version I think.

    @ParadoxIT, @MichaelHilgers About tenant detection problem, there was a bug in ABP framework and we have fixed it. So if you upgrade your ABP nuget packages, this should be fixed.

    If you don't want to upgrade ABP version, you can implement a custom tenant resolver, see <a class="postlink" href="https://aspnetboilerplate.com/Pages/Documents/Multi-Tenancy#determining-current-tenant">https://aspnetboilerplate.com/Pages/Doc ... ent-tenant</a> to fix this problem.

    Thanks.