-
Notifications
You must be signed in to change notification settings - Fork 804
Database One application with different database per customer
Because many people ask for multitenancy with separate database per customer, instead a classic multitenancy with TenantId, I've created this page to answer and clear process using IIS location functionality.
Based on this https://github.com/volkanceylan/Serenity/issues/3661 and https://serverfault.com/questions/713152/how-can-i-split-out-connection-strings-for-an-iis-site-but-maintain-a-shared-ap
If your goal is one application with multiple database for different customer, you can use location functionality of IIS. To obation this, you have to extrapolate the connection string from your Web.config. You have to deploy application with a super directory that contain a Web.config with connection strings and another folder with your App and the Web.config without connection strings. An image can clear this concept:
This first Web.config under wwwroot contain connection string
<?xml version="1.0" encoding="utf-8"?>
<!--<?xml version="1.0" encoding="utf-8"?>-->
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<location path="Customer1">
<connectionStrings>
<add name="Default" connectionString="xxx.... first database default" />
<add name="SWData" connectionString="xxx.... first database data" />
</connectionStrings>
</location>
<location path="Customer2">
<connectionStrings>
<add name="Default" connectionString="xxx.... second database default" />
<add name="SWData" connectionString="xxx.... second database data" />
</connectionStrings>
</location>
<location path="Customer3">
<connectionStrings>
<add name="Default" connectionString="xxx.... third database default" />
<add name="SWData" connectionString="xxx.... third database data" />
</connectionStrings>
</location>
</configuration>
Under your application folder is second Web.config, with all configurations except connection strings
Now have to set virtual folder for IIS. If your application is www.myapp.cloud a virtual directory is www.myapp.cloud\Customer1 (that match with ) and so on.
In Azure go under web app application settings, virtual directory and set it
First virtual path: Virtual Path = /Customer1 Physical Path = \site\wwwroot\yourapp Type = Application
Second virtual path: Virtual Path = /Customer2 Physical Path = \site\wwwroot\yourapp Type = Application
Users that use the link www.myapp.cloud\Customer1 use first database, user that use link the link www.myapp.cloud\Customer2 use second database, and so on.
Copyright © Serenity Platform 2017-present. All rights reserved.
Documentation | Serene Template | Live Demo | Premium Support | Issues | Discussions