Multi-Tenancy with ASP.NET Core

Jun 11, 2019 4:23:15 PM / by Omkar Choudhari

What is Multi-Tenancy?

A multi-tenant web application is one that responds differently depending on how it is addressed – by the tenant.

This kind of architecture has become very popular, especially with Enterprise and SaaS products due to the fact that a single code base and deployment can serve many different tenants. Since all tenants use the same application, it’s easier for maintenance and upgrades.

It’s being adopted by providers like Salesforce , Office365, Slack and Basecamp. A single instance of a Multi-Tenant application handles multiple clients and Each “client” is called a “tenant.”

Every tenant interacts with the same code base. However application provides :

  • Isolation of tenant data - Each tenant gets their own app configuration and their data is isolated from other tenants
  • Database Options : by providing a common or separate database depending on client’s needs.
  • Hybrid Approach : Some SaaS Providers also enable storing subscribers data during a free trial, in a common database and when a customer purchases a subscription , then a separate database is provisioned for him.
  • User Management : Every tenant has its own users, roles, permissions, settings... and uses the application completely isolated from other tenants.
  • Configuration options: Different UI by allowing theme changes like uploading organization logo and displaying different dashboard for each tenant.
  • Customizations to some features – allowing features to be turned on or off depending upon what the tenant wants to see in the application.

Your multi-tenant application must employ a way to identify a tenant and find out for which tenant is an HTTP request received for.

How Asp.Net Zero identifies and resolves tenants

ASP.NET Zero is a web application development framework based on ASP.Net Core. (https://aspnetzero.com)

ASP.NET Zero framework supports and implements multi-tenancy. Let us look at how the application can identify tenants for storing data , and how to show tenant data depending on HTTP requests.

There can be different strategies for identifying and resolving tenants , like :

  • Current user Claim (For authenticated user)
  • Tenant-specific sub-domain: For example https://tenant1.waiinsure.com would show the page/data for tenant1 or https://tenant2.waiinsure.com would show page/data for tenant2. This serves as a gateway to separate between different tenants.
  • Http Header: tenant name = “Contoso” (for API clients & SPAs)
  • Http Cookie: for asp.net MVC applications

Single Entry Login Page for all tenants

In order to provide a seamless login experience, your application should have Single entry point for all tenants.

 

Tenants-01-01

This approach is more intuitive wherein it’s not necessary to remember the tenant URL. For example all tenants have a common login page with URL https://app.waiinsure.com .

A tenant user logs in with his organizational email address user1@tenant1.com or user1@tenant2.com.

Even if we do not know the tenant URL i.e. , https://tenant1.waiinsure.com , with a custom approach, The application code simply grabs the tenant name from the tenant username (organizational email address)and authenticates the user.

The it sends a request to the database. And if the database schemas is set up correctly, only that tenant specific data is retrieved and he is redirected to a tenant unique landing page. This is achieved with some customization in the Asp.net zero framework.

Common Login page https://app.waiinsure.com

 

GIF1
 

Above figures show users of two different organizations logging in at the common login page and getting authenticated by Asp.Net zero application to view their company specific dashboard.

In order to implement this approach, the important consideration is tenant identification.

If  you have any questions please write to me at kirti.kulkarni@waiin.com.

 

Topics: ASP.NET Core, ASP.NET Zero, Multi-Tenancy, SaaS, ASP.NET Boilerplate, Framework, ASP.NET

Omkar Choudhari

Written by Omkar Choudhari

Omkar brings business and technology together at WAi. With his customer-centric approach and years of experience into IT sector, he provides direction and strategy to build great products, services and platforms that fosters collaboration, improves collective business effectiveness and makes the world more productive and efficient.