Base solution for your next web application
Open Closed

sub-domain problem on first visit to page #6029


User avatar
0
BobIngham created

.net core, angular, 5.4.1 I have a multi-tenanted solution set up at [websitehere]. The system is hosted on azure [websitehere.azurewebsites.net] and my domains are held at GoDaddy. I set up a new tenant and send the link to my customer by email.

When the customer clicks on the link s/he is directed to the website and although we can see the sub-domain in the browser bar:"subdomain.website.api" the tenant is not picked up by the system and the customer is unable to login. However, I can sit with the customer and login using the host admin details with the sub-domain showing in the browser bar which logs me into the host account. I can then impersonate a user in the tenant account, return to my host account and logout. Now when the user traverses to "subdomain.website.api" the tenant is found and the customer is able to login. I have spent a few calls and hours with GoDaddy and they confirm my DNS settings are correct:

I am told my Azure settings are also fine:

My appconfig.json is setup as standard:

{
  "remoteServiceBaseUrl": "https://projectname.api",
  "appBaseUrl": "https://{TENANCY_NAME}.projectname.ui",
  "localeMappings": [
    {
      "from": "pt-BR",
      "to": "pt"
    },
    {
      "from": "zh-CN",
      "to": "zh"
    }
  ]
}

Everything points to a code problem and i have placed comments in account.component.htm,l to verify the tenant is not found on first visit to the sub-domain. Why is the tenant not being picked up on first visit to the page, subdomain.website.api? Any help much appreciated because this is becoming a bit of a show-stopper for me.


12 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team
    {
         "remoteServiceBaseUrl": "https://{TENANCY_NAME}.nuagecare.io",
        "appBaseUrl": "https://{TENANCY_NAME}.nuagecare.net"
    }
    

    The same configuration should be done in the nuagecare.io domain name https://docs.aspnetzero.com/documents/zero/latest/Development-Guide-Angular#configuration

  • User Avatar
    0
    BobIngham created

    @maliming, thanks for the reply but I still have no luck. My appconfig.json file looks as follows:

    {
      "remoteServiceBaseUrl": "http://{TENANCY_NAME}.projectname.api",
      "appBaseUrl": "http://{TENANCY_NAME}.projectname.ui"
    }
    

    I have changed my Azure settings accordingly:

    I am expecting the page to pick up the tenant from the sub-domain in the browser bar. I have applied some debug statements in the login page. Here is an example after I have impersonated a user in the tenant and logged out:

    If you traverse to [subdomain.websitehere] you will see that the debug value for tenant session object is null.

    Any ideas anyone, I'm kind of getting a bit desperate now and definitely getting balder as I tear more of my hair out....

  • User Avatar
    0
    maliming created
    Support Team

    It's seems the issue is exist in http://beverley.nuagecare.io/api/services/app/Session/GetCurrentLoginInformations project. It does not correctly resolve tenant information

    In order to rule out the problem of azure. You can deploy multiple domain name environments locally, modify the domain name in your computer's Host file, and then bind the domain name in IIS, which helps to debug the problem.

    If you have difficulty with this, you can exclude the privacy data and send the project to: [email protected]

  • User Avatar
    0
    BobIngham created

    @maliming, I will investigate further by placing some log statements in the GetCurrentLoginInformations method on the server and also place some console.log statements in angular. I'm not sure what this means exactly (in terms of what I physically have to do):

    In order to rule out the problem of azure. You can deploy multiple domain name environments locally, modify the domain name in your computer's Host file, and then bind the domain name in IIS, which helps to debug the problem.

    So I may come back to you to explain this if I reach another dead-end. Thanks for your assistance and guidance so far.

  • User Avatar
    0
    BobIngham created

    Hi @maliming, I reached a dead-end and I have sent you a copy of my project by email. I'm hoping you can help me in this because I'm fairly much at my wits end! Cheers, Bob

  • User Avatar
    0
    maliming created
    Support Team

    Ok, I will check it out.

  • User Avatar
    0
    maliming created
    Support Team

    I am having some problems trying to building your project. What is your local sdk version?

    or Would it help if I tested the sub-domain successfully using the ASPNET ZERO Demo Project?

  • User Avatar
    0
    BobIngham created

    Angular cli 6.0.8, Node 8.11.4, OS Win32, Angular 6.0.0 @angular-devkit/architect 0.6.0 @angular-devkit/build-angular 0.6.0 @angular-devkit/build-optimizer 0.6.0 @angular-devkit/core 0.6.8 @angular-devkit/schematics 0.6.8 @angular/cdk 6.4.7 @angular/cli 6.0.8 @angular/compiler-cli 6.0.4 @ngtools/webpack 6.0.0 @schematics/angular 0.6.8 @schematics/update 0.6.8 rxjs 6.1.0 typescript 2.7.2 webpack 4.6.0 The .net core soluition is gramework 4.6.1 but the Mongo and BlobStorage projects and .NET standard 2.0 Does that help? Thanks for your help.

  • User Avatar
    0
    BobIngham created

    @maliming, if my understanding is correct the user navigates to the sub-domain and the first thing the browser does is to request the page from the server. Where in the .net code does it read the url to ascertain the tenant and set the session?

  • User Avatar
    0
    maliming created
    Support Team

    https://aspnetboilerplate.com/Pages/Documents/Multi-Tenancy#determining-current-tenant

    DomainTenantResolveContributer: Tries to resolve tenancy name from an url, generally from a domain or subdomain. You can configure the domain format in the PreInitialize method of your module (like Configuration.Modules.AbpWebCommon().MultiTenancy.DomainFormat = "{0}.mydomain.com";). If the domain format is "{0}.mydomain.com" and the current host of the request is acme.mydomain.com, then the tenancy name is resolved as "acme". The next step is to query ITenantStore to find the TenantId by the given tenancy name. If a tenant is found, then it's resolved as the current TenantId.

    There is no problem with your angular project. The Host project does not correctly determining the current tenant. If you want to test, you can request it.http://beverley.nuagecare.io/api/services/app/Session/GetCurrentLoginInformations

    The tenant information will be returned normally. But your host project is not working correctly.

    Configuration.Modules.AbpWebCommon().MultiTenancy.DomainFormat = _appConfiguration["App:ServerRootAddress"] ?? "http://localhost:22742/";

    Has your App:ServerRootAddress configured the DomainFormat correctly?

  • User Avatar
    0
    BobIngham created

    @maliming, Brilliant, I feel we're going in the right direction. In Nuagecare.Web.Host\Startup\NuagecareWebHostModule.cs, method PreInitialize() I have:

    public override void PreInitialize()
    {
        Configuration.Modules.AbpWebCommon().MultiTenancy.DomainFormat = _appConfiguration["App:ServerRootAddress"] ?? "http://localhost:22742/";
        Configuration.Modules.AspNetZero().LicenseCode = _appConfiguration["AbpZeroLicenseCode"];
    }
    

    In my appsettings.production.json:

    "App": {
        "ServerRootAddress": "https://projectname.api/",
        "ClientRootAddress": "https://projectname.ui/",
        "CorsOrigins": "https://projectname.ui/"
    },
    

    I just know I'm going to feel really stupid when you tell me to change these values to:

    "App": {
        "ServerRootAddress": "https://{TENANCY_NAME}.projectname.api/",
        "ClientRootAddress": "https://{TENANCY_NAME}.projectname.ui/",
        "CorsOrigins": "https://{TENANCY_NAME}.projectname.ui/"
    },
    

    Is that where the problem lies?

  • User Avatar
    0
    BobIngham created

    Hi @maliming. Thanks for all the help. The documentation is a little unclear in that it does not specifically mention that appconfig.json should be changed in angular:

    {
      "remoteServiceBaseUrl": "https://{TENANCY_NAME}.projectname.api",
      "appBaseUrl": "https://{TENANCY_NAME}.projectname.ui"
    }
    

    and appsettings.production.json in .NET core:

    "App": {
            "ServerRootAddress": "https://{TENANCY_NAME}.projectname.api/",
            "ClientRootAddress": "https://{TENANCY_NAME}.projectname.ui/",
            "CorsOrigins": "https://{TENANCY_NAME}.projectname.ui/"
        },
    

    I will leave this here on the off-chance that it may help someone else. Thanks again, @maliming.