I am developing a web application which will be run by multiple companies. Each company will have its own instance of that web application. And each company has its own database (the web applications and databases will be running on the same server).
Each of these instances should be talking to one single Web API application to retrieve data from their database for that specific company.
Now I am wondering whether it is a good practice to change the database connection string in the Web API application based on the request origin? Or am I overlooking something?
There are things that need to be clarified:
Anyways, the application is pretty funny. You need to have a connection string factory that returns connection string based on your request. You will need to decide where to put your connection string. Database or maybe some config settings?
Alternatively you can consider hosting your WebAPI with ASP.NET web sites and have different connection string for each tenant. This would also work unless you don't want to share database connection string with people who have access to websites.