views:

35

answers:

2

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.

+1  A: 

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(?)

Shoban
+1  A: 

There are 2 ways atleast to do it:

  • Create 10 IIS sites, each pointing to it's own directory, place as much of the functionality as possible in dll's in the GAC. You then have shared code base. But still some individual site data on disk.
  • Create 10 IIS Sites, each pointing to the same directory. Place all 10 connection strings in the web.config. In your code have functionality that selects the correct connection string for the request.

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.

Shiraz Bhaiji