1

I have a Windows 2008R2 server with IIS, running one site (ASP.NET4.5). All the parameters are written in web.config file.

I have to add a new site, that will run on the same code (same root folder) as the first one, but will read parameters like sql connection strings etc. from its own config file, not from first site web.config.

How can I do that?

Is it possible to run the second site in different app pool? Both sites will run the same .NET version of course.

Thank you!

2 Answers 2

0

Yes. I've served the exact same code/files from multiple AppPools for years; it works fine.

But all instances will read web.config identically since Microsoft's standard functionality wasn't written to do what you're trying to do. So you will have to implement your own custom solution for determining what instance the code is running under and choose the appropriate configuration variables based on that. You could either store your config data in a custom config section within web.config (defined in "configSections") or have a separate .config file somewhere else.

What I usually do is switch the code's behavior based on the path to the IIS Application it's running under (i.e. the path). E.g. if the site is being served up under "/example1", I pick one set of config data, and if it's served up under "/example2" it gets another set. (Note that you'll also want to handle the config for the Dev Server's URL when you're running your site through VisualStudio.)

0

Another solution is to maintain two separate root folders, each with their own web.config, but create links to the directories/files in the other root folder, so you only have to maintain the source in one location.

Powershell goes something like this to create the links the first time:

function mklink { cmd /c mklink $args }

Get-ChildItem "root-source" | Where {($_.PSIsContainer) -band ($_.Name -ne "web.config")} | mklink /d ("root-links-are-here" + $_.Name) $_.FullName

Get-ChildItem "root-source" | Where {(!$_.PSIsContainer) -band ($_.Name -ne "web.config")} | mklink ("root-links-are-here" + $_.Name) $_.FullName

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .