Base solution for your next web application
Open Closed

Configuration of multi tenancy #2704


User avatar
0
DennisAhlin created

Hi! I've been trying to get this to work for a few days now. How am I supposed to configure host and client to be able to use multi tenancy, both in localhost, staging and production servers? Solution is .NET Core + Angular 2. In all environments, when I go localhost:4200/staging.mydomain.com/mydomain.com or default.localhost:4200/default.staging.mydomain.com/default.mydomain.com i get the centered loading spinner and after a while a modal with "An error occured/Error detail not sent by server.". I can't see any failed requests in the Network view in Chrome Developer Tools.

Localhost: Currenty I have configured angular appconfig.json like this:

{
  "remoteServiceBaseUrl": "http://localhost:22742",
  "appBaseUrl": "http://{TENANCY_NAME}.localhost:4200"
}

and .Net appsettings.json like this:

"App": {
    "WebSiteRootAddress": "http://localhost:22742"
  }

Staging: Angular appconfig.json:

{
  "remoteServiceBaseUrl": "http://{TENANCY_NAME}.api.staging.mydomain.com",
  "appBaseUrl": "http://{TENANCY_NAME}.staging.mydomain.com"
}

.Net appsettings.json:

"App": {
    "WebSiteRootAddress": "http://{TENANCY_NAME}.staging.mydomain.com/"
  }

Production: Angular appconfig.json:

{
  "remoteServiceBaseUrl": "http://{TENANCY_NAME}.api.mydomain.com",
  "appBaseUrl": "http://{TENANCY_NAME}.mydomain.com"
}

.Net appsettings.json:

"App": {
    "WebSiteRootAddress": "http://{TENANCY_NAME}.mydomain.com/"
  }

Please help, what am I doing wrong? :geek:


12 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    We had a similar issue before and this answer helped to solve it #2573@a812f81a-3dfa-47d2-bf49-aad54918f40a.

    To make it work, you need to upgrade ABP to latest version in your project.

    Please let us know if it does not work for you.

    Thanks.

  • User Avatar
    0
    DennisAhlin created

    I have now updated to ABP 1.5 and AN0 3.3.0 and trying with this configuration.

    Localhost: This works, but when browsing localhost:4200 I get to login without tenant selector and when logged in I am logged in on default tenant. And when browsing default.localhost:4200 i get the same error as before. I assume that default... does not work because I need to configure IIS or hosts file in some way to redirect default.localhost to localhost? How can I do that?

    angular appconfig.json:

    {
      "remoteServiceBaseUrl": "http://{TENANCY_NAME}.localhost:22742",
      "appBaseUrl": "http://{TENANCY_NAME}.localhost:4200"
    }
    

    .Net appsettings.json:

    "App": {
        "WebSiteRootAddress": "http://{TENANCY_NAME}.localhost:22742/",
        "CorsOrigins": "http://localhost:4200/, http://default.localhost:4200"
      }
    

    Staging: Now "works" with this configuration. However, when I go to <a class="postlink" href="http://staging.mydomain.com">http://staging.mydomain.com</a> I get the login screen without the tenant selection section and when I log in I get logged in as default. The same behaviour as if I go to <a class="postlink" href="http://default.staging.mydomain.com">http://default.staging.mydomain.com</a> (where it is expected).

    angular appconfig.json:

    {
      "remoteServiceBaseUrl": "http://{TENANCY_NAME}.api.staging.mydomain.com",
      "appBaseUrl": "http://{TENANCY_NAME}.staging.mydomain.com"
    }
    

    .Net appsettings.json:

    "App": {
        "WebSiteRootAddress": "http://{TENANCY_NAME}.staging.mydomain.com/",
        "CorsOrigins": "http://staging.mydomain.com/,http://default.staging.mydomain.com/"
      }
    
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    When you enter <a class="postlink" href="http://staging.mydomain.com">http://staging.mydomain.com</a> it is normal not seeing tenant selection because it is considered as host in that case but you should be able to login as host admin in that case.

    If you are not logged in as host admin, then we can check it again.

    Thanks.

  • User Avatar
    0
    DennisAhlin created

    It still doesn't work to go to default.localhost:4200, how can I solve that?

    In staging, though, suddenly I can only log in as host admin. Even when I go to default.staging.mydomain.com I cannot log in with default tenant admin credentials, only with host admin, and I get logged in as host admin?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    It still doesn't work to go to default.localhost:4200, how can I solve that?
    

    I think it is not possible to make this work on localhost. You can publish your project to local IIS and configure windows's host file for a dumm url and test subdomain architecture in this way.

    For your staigng, value of remoteServiceBaseUrl in angular client config and WebSiteRootAddress of host app must be same. Can you try in that way ?

    Thanks.

  • User Avatar
    0
    DennisAhlin created

    Ok, I will try with IIS solution locally.

    I did have a bad config value in WebSiteRootAddress. It was http://{TENANCY_NAME}.staging.mydomain.com and I have now changed to http://{TENANCY_NAME}.api.staging.mydomain.com. It did no difference, though. I can't go to any other tenant either, like tenant1.staging.mydomain.com. I get the same error modal there even though the first <a class="postlink" href="http://tenant1.api.staging.mydomain.com/AbpUserConfiguration/GetAll">http://tenant1.api.staging.mydomain.com ... ion/GetAll</a> OPTIONS request gets a 204 response.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    I assume you have restarted your app after this configuration change, right ? I'm asking just to be sure.

    Also did you configured IIS to accept request with subdomain for <a class="postlink" href="http://tenant1.api.staging.mydomain.com">http://tenant1.api.staging.mydomain.com</a> ?

  • User Avatar
    0
    DennisAhlin created

    Yes, I restarted the app, dropped the entire database, redeployed it and emptied all cache in the host admin interface. Hopefully the setting shouldn't be trailing somewhere.

    I can go to all <a class="postlink" href="http://tenant1.api.staging.mydomain.com">http://tenant1.api.staging.mydomain.com</a>, <a class="postlink" href="http://default.api.staging.mydomain.com">http://default.api.staging.mydomain.com</a> and <a class="postlink" href="http://api.staging.mydomain.com">http://api.staging.mydomain.com</a> and see the Swagger interface.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Then we can try to help you via TeamViewer on monday, what do you think about it ? It is hard to find problem in this way because similar configuration worked for us in our environment.

    If you are OK with TeamViewer support, please send an email to <a href="mailto:[email protected]">[email protected]</a>. We are available between 09:00 to 17:00 (UTC+03:00).

    Thanks.

  • User Avatar
    0
    DennisAhlin created

    So, for anyone with the same problem. The error was that the App:WebSiteRootAddress had a trailing slash. Also, currently you have to add every subdomain into App:CorsOrigins with trailing slash.

    Thank you Zero for very good support!

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @DennisAhlin,

    Thanks for your time and finding the bug as well :).

  • User Avatar
    0
    DennisAhlin created

    I figured out how to setup domain tenant recognition on localhost reasonably simple.

    If anyone is interested, answer this thread and I'll write a guide :)