Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

I pretty sure I did this once years ago in order to have a different db connection string for each instance of a website. My guess was that there was a virtual directory for each instance of the website which only contained a web.config with instance specific settings in and then inside each of these virtual directories was an app which referenced the source code (which included a shared web.config).

Thus the trick, if I remember correctly, was, for a given website, to have a virtual directory which only contained a web.config. The values in this would be inherited by that virtual directory's sub-app.

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top