views:

777

answers:

2

I have a web application which I want to use for multiple business areas. I do not want to have multiple instance of the web app code on the web server.

So as an example: I have //MyWebSite/Virtual_Directory_1 refers to c:\Inetpub\wwwroot\MyWebApp pointing to Database_A What I want is to setup another Virtual Directory as follows: //MyWebSite/Virtual_Directory_2 refers to c:\Inetpub\wwwroot\MyWebApp pointing to Database_B.

The I was thinking of doing this was by having separate web.config files, but I am not sure how to actually do this.

Any help will be appreciated.

Thanks Parag

A: 

You can split your configuration to multiple files and you can also create 1 or more virtual directories in IIS for a single Physical directory. However this means you would have 2 instance of your web application available on your web container but both utilizing the same configuration files no matter they are split on multiple files.

You can also have a web.config file for each sub directory in your web application and each file can override its parent web.config settings (Not every thing is overridable).

To create a virtual directory on the run dialogue box type inetmgr... The IIS Manager will open up. Right click on the default web site if on the client OS and select New then Virtual Directory. Virtual Directory setup wizard will appear. Follow the simple steps it has to offer and you end up creating 2 virtual directories for a single source directory.

If you just want to have different functionalities (i.e. pointing to different database) for each web app instance then consider web.config configuration sections instead.. and have database connection strings saved against a key in app settings and load the specific database connection string considering which resource is accessed.

Have a look at the article on this location:

S M Kamran
A: 

One way of doing it I guess would be to have a shared web.config file and then have multiple connection strings in that config file that match the virtual directory name.

<connectionStrings>
    <add name="VirtualDir1" connectionString="data source=BLAHBLAH" />
    <add name="VirtualDir2" connectionString="data source=BLAHBLAH" />
</connectionStrings>

When getting the connection string simply reference like:

ConfigurationManager.ConnectionStrings(Request.ApplicationPath).ConnectionString

Although to be honest I think a little time spent with build projects and having multiple copies of the code with their own config files will save you pain in the long run.

Justin Wignall