Reputation: 2009
I have inherited some very old asp code. I need to resolve a design problem because of it, described below.
I have 3 customers... Foo, Bar and Baz.
I have a folder called...
c:\WebSites\Site.v15.07
I have 3 websites in IIS defined as...
Website.Foo
Website.Bar
Website.Baz
They all point to the 15.07 directory.
There are 3 other folders called...
c:\WebConfigurations\Foo
c:\WebConfigurations\Bar
c:\WebConfigurations\Baz
... which all contain client specific files for each of the 3 sites. Uploaded images etc.
Each of the 3 customers has their own database that the website sits on.
I need to set (ideally, using a web.config) the connection string for each of the 3 sites.
If I put this in the web.config in the root of the website directory, they will all share the same setting.
Is there a way of adding the settings/web.config in IIS at the "website" level so that each site can be set differently?
Upvotes: 1
Views: 2516
Reputation: 74949
Put only the common configuration in Web.config
in the application folder.
When the application is first loading, programmatically load the client-specific config file from the respective folder and programmatically merge the info into the configuration info in memory.
Example of programmatically editing configuration info in memory:
Change a web.config programmatically with C# (.NET)
var configuration = WebConfigurationManager.OpenWebConfiguration("~");
var section = (ConnectionStringsSection)configuration.GetSection("connectionStrings");
section.ConnectionStrings["MyConnectionString"].ConnectionString = "Data Source=...";
In your case you'll want to make two calls to WebConfigurationManager.OpenWebConfiguration
, one to open the application config and once to load the client configuration. Then copy data from client config to the in-memory application config (don't call Save()
per the referenced question--that's a different use case).
Upvotes: 1