views:

1171

answers:

4

Is it possible using virtual directories and/or virtual applications to set up two web sites that share the same application code (aspx pages etc.) but have different web.config files? The sites and code are residing on the same server running on the same IIS.

I am using IIS 6.

A: 

should be, the web.config in the virtual application will be used. If the layout is hierarchical you may need to look out for web.config inheritance

Pharabus
I should add, you would need 2 physical copies of the application code as a web.config would be needed in each
Pharabus
+4  A: 

The short answer is no if you want to keep the code in one place. Probably the best solution is to have the application loading a custom config file based on what you determine the site to be (presumably host header?).

Something like ConfigurationManager.OpenExeConfiguration may be useful.

I guess an alternative is to come up with a configuration convention where you have everything in the one file and use GetSection (with some kind of app specific prefix) to get the specific settings for what you want.

RichardOD
Yeah, I know this can be done in other ways. I was just hoping I could do it without changing the existing code.
Jakob Christensen
+1  A: 

This is simply not possible.

Why ???

Becuase the asp.net worker process will read the default configuration file from the physical folder where the application is physically residing. Virtual directories have got nothing to do with web.config. It is just used by webserver(IIS) to map to a particular physical directory as root of the website.

Thanks.

this. __curious_geek
A: 

I'm assuming you have application A, application B, application C and so on, that are all exactly the same, except they differ by some configuration properties as defined in their web.config files.

Of course this is possible - easiest way is to set up the project as a web application, then compile, then share that dll amongst the applications. You can use the GAC is you wish.

You can set up individual sites in IIS that point to the a shared directory (or use a virtual directory in each) where all the logic sits, but you can't share the app_code folder.

EDIT

RichardOD has the best answer above, and I have implemented something similar before. Basically, I set up a custom config file that is references by the web.config (to prevent app restarts when I make changes to it). This file is read by host name, and contains specific properties on a per-host basis.

All I do is add host headers to IIS, and an entry for that host in the custom config file. Done.

ScottE