The same ASP.NET site on multiple subdomains, but in different databases?

Suppose I want to create 10 websites in IIS, each of which points to the same site on the local hard drive, each of which works with the same code, but on different subdomains.

subdomain1.domain.com, subdomain2.domain.com, ..., subdomain10.domain.com

How can I add several connection lines to my web.config file and bind each connection line to a different subdomain?

I want to do this because each site will have a different database with different data.

+6
sql-server
source share
2 answers

Since the web.config is common to all sites, you can add several connection strings similar to this for each subdomain.

 <connectionStrings> <add connectionString="" name="subdomain1"/> <add connectionString="" name="subdomain2"/> </connectionStrings> 

Then you can check the current url using

 HttpContext.Current.Request.Url.AbsoluteUri 

and then use the correct connection string (?)

+2
source share

There are two ways to do this:

  • Create 10 IIS sites, each of which points to its own directory, put as many features as possible in the dll in the GAC. Then you have a common code base. But still some individual site data on disk.
  • Create 10 IIS sites, each of which points to the same directory. Put all 10 connection lines in web.config. Your code has functionality that selects the correct connection string for the request.

In fact, for the second you may not need 10 sites. Just ask DNS to list all 10 sites on the same IP address.

However, you should consider if it is more than what it costs. Installing a script that automatically copies a site to 10 locations might be the best approach.

+1
source share

All Articles