Reputation: 2288
Consider that I want to create 10 websites in IIS, each of them pointing to the same website on local hard drive, each one running the same code, but on different subdomain.
subdomain1.domain.com, subdomain2.domain.com, ..., subdomain10.domain.com
How can I add multiple connection strings in my web.config file and bind each connection string to a different subdomain ?
I want to do this because every website will have a different database with different data.
Upvotes: 7
Views: 2259
Reputation: 65391
There are 2 ways atleast to do it:
Actually for the second one you may not need 10 sites. Just get the DNS to point all 10 sites to the same IP.
However, you should consider if it is more work than it is worth. An install script that automatically copies the site to 10 locations may be the best approach.
Upvotes: 1
Reputation: 23016
Since the web.config
file is common for all the sites, you can add multiple connection strings like this for each sub domain.
<connectionStrings>
<add connectionString="" name="subdomain1"/>
<add connectionString="" name="subdomain2"/>
</connectionStrings>
Then you can check for the current url using
HttpContext.Current.Request.Url.AbsoluteUri
and then use the correct connection string(?)
Upvotes: 3