Base solution for your next web application
Open Closed

Do I need a subdomain per tenancy? #2530


User avatar
0
bilalhaidar created

Hello I am reading through the development guide and noticed the configuration for multitenancy applications.

Do I have to use a separate subdomain for each tenant in the application? Are there alternatives?

Thanks Bilal


10 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    There are two alternatives out of the box:

    1. Use a part of domain as you tenancy name (subdomain or full domain).
    2. Don't use url to determine the tenant. In that case, you can select tenant in the login page, as you are generally doing in development.

    Another alternative is sending Abp.TenantId header in every request as your tenant id. Server side understand it (see <a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Multi-Tenancy#determining-current-tenant">http://www.aspnetboilerplate.com/Pages/ ... ent-tenant</a>).

    If you can offer any other alternative, please write us.

  • User Avatar
    0
    bilalhaidar created

    So I could use a sub-domain or append the tenant name to end of domain? something like <a class="postlink" href="http://mydomain.com/t1">http://mydomain.com/t1</a> ?

    When users logs into the system, can't at that stage conclude the tenant id from the db? What has been configured before that user 1 belongs to tenant 1?

    Thanks

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi Bilal,

    For the first question, yes you can use a format like <a class="postlink" href="http://mydomain.com/t1">http://mydomain.com/t1</a> or <a class="postlink" href="http://mydomain.com/t2">http://mydomain.com/t2</a>, no problem. I'm not sure if I understand the second question very well but let me try to answer as much as I understand :).

    When user uses a url like <a class="postlink" href="http://mydomain.com/t1">http://mydomain.com/t1</a>, we already know the tenant. But, when user uses a url like <a class="postlink" href="http://mydomain.com/">http://mydomain.com/</a>, then we don't know the tenant and we ask to user for a tenancy name.

    Do you have a different case ? If so, can you explain it a bit more detailed.

    Thanks.

  • User Avatar
    0
    bilalhaidar created

    Thanks for the input :-)

    What I meant is that, an Admin would map a user to a tenant. In this case, the DB already has information that user1 belongs to tenant1. Correct?

    Maybe I am not understanding well concept of multi-tenants.

    Thanks a lot,

    Regards

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi Bilal,

    In AspNet Zero a user can belong to a tenant or host. But consider tenant1 has a user with username admin and tenant2 has a user with username admin. In this case we cannot know admin user belongs to which tenant.

    If we can find tenant from website's url (like <a class="postlink" href="http://www.mycompany.com/tenant1">www.mycompany.com/tenant1</a> or tenant1.mycompany.com) then no problem. But if we cannot find tenant from website's url we need to ask user for a tenancy name.

    You can choose to use a unique username among all tenants but it is a hard thing to do. In AspNet Zero tenant databases can be stored in different servers. In such a scenario it is even harder to have a unique username amont all tenants.

    I hope this will help you.

    Thanks.

  • User Avatar
    0
    bilalhaidar created

    Correct. Thanks a lot for the explanation.

  • User Avatar
    0
    bilalhaidar created

    I am trying to configure my multi-tenant website as :

    WebSiteRootAddress to be <a class="postlink" href="http://localhost:6240/">http://localhost:6240/</a>{TENANCY_NAME}

    When I try to access website as:

    <a class="postlink" href="http://localhost:6240/Default">http://localhost:6240/Default</a>

    I get 404 Not Found

    Any idea? Thanks

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    I give you such an example of <a class="postlink" href="http://www.mycompany.com/tenant1">www.mycompany.com/tenant1</a> but this is a problematic usage. We suggest you to use <a class="postlink" href="http://www.tenant1.mycompany.com">www.tenant1.mycompany.com</a>.

    In <a class="postlink" href="http://www.mycompany.com/tenant">www.mycompany.com/tenant</a> version you need to configure ASP.NET routing to make it work. Also it will be a problem for cookies in that version as well.

    Thanks.

  • User Avatar
    0
    bilalhaidar created

    How to configure subdomains locally while development? Or I don't need to? I can specify Tenant or now, and on production I configure subdomains?

    Thanks

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You don't need to configure subdomains for development. But if you want to do that, you can use windows's host file in order to map some addresses to your local ports.