开发者

Same ASP.NET website on multiple subdomains but different databases?

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 s开发者_Go百科trings 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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜