janaks09/NetCoreSaaS

Dynamic Tenants

Closed this issue · 2 comments

Is it possible to add tenants without restarting the app? How about the urls/hostnames? How can you add them dynamically for each dynamically created tenants?

Yes, you can. All you need to do is add new tenant information in Tenant table.
Tenant table looks like this.
tenanttable

In HostName, you need to add URL of a tenant like company1.example.com or company2.example.com.

If a user tries to access company1.example.com, first it will fetch hostname in Tenant table if found it will get other information and setup environment for that tenant else you can redirect that request to common landing page i.e. example.com (or as per your preferred location). This is all dynamic. No restart required.

For URL and hostnames, you need to setup wildcard record in your DNS management portal. Eg. you need to map *.hostname.com to IP address of application host. With this setup, you are redirecting every subdomain request of your domain to your SaaS app's IP address and in-app we have logic to check whether that domain (or tenant) is registered or not.

To add new tenant information, you have to build separate UI. It can be something like signup page for anyone or admin UI where only admin is allowed to add new tenant. Then host your separate UI on example.com or www.example.com. With this setup, now you have example.com and www.example.com as marketing or SaaS landing page and *.example.com for tenants.

Feel free to open this issue if you are not clear.