Multiple web sites, one common code base and different configuration files
I have two web sites in IIS like
http://domainA.com
http://domainB.com
I would like to use the same code for these web sites but a different web.config files. Is this possible? I store database connectionstrings etc in the web.config files, all the other code in the applications are the same.
I have tried some different approches with creating a folder structure like
-Root
- Domain A
- web.config for domain A
- Code
- Virtual Directory to Source Code
- Domain B
- web.config for domain B
- Code
- Virtua开发者_运维知识库l Directory to Source Code
- Source Code
I will then point the website for domain A to "Root/Domain A" and domain B to "Root/Domain B" but the problem is then that the code must be accessed one level down, like
http://domainA.com/Code/
http://domainB.com/Code/
Any ideas?
I will base my answer on the assumption that you are writing custom code rather than using an out of the box solution such as DNN or SharePoint.
One solution that comes to mind to keep a common code base is to maintain your website specific configuration settings in your database instead of the web.config. You can keep your database structure fairly dynamic by using a set of name/value pairs. You would of course need to take this into account in the design of your application and plan for it in your database. This gives you the advantage of only having a single code base as well as a single web.config. If you need to maintain content in separate databases for each site, the connection string info to those content databases can be one of the name/value pairs in your configuration database.
You can even take this one step further by having a single website in IIS for all domains as well (unless you will be using SSL, in which case separate IIS sites would be better). You would need to add host headers to the website and then look for the host header in your code to determine what settings to use and what content to serve. You would lose the ability to create separate app pools so you should check your requirements if this is a feasible option for your situation.
This is actually a similar model to how both DNN and SharePoint work but can certainly be done in a custom application as well.
精彩评论