Can I use multiple web.config ?

  • Thread starter Thread starter George
  • Start date Start date
G

George

Hi,

Is it possible to specify the location of a web.config file in an
ASP.NET application?

I have one ASP.NET application which is to be hosted on 2 web sites in the
same web server. I want to configure the 2nd web site as virtual directory
so that the 2 web sites are pointing to the same application. However, there
are different configuration settings for the 2 web sites, so that accessing
these 2 sites' same ASP.NET application will have different outcome.


Thanks and Regards,
George
 
No, you cant use multiple web.config for one application. If you tell us
what information you are getting it from web.config file. Then we can
provide with different options for doing that.
 
Thanks for your reply.

Suppose I have 2 websites "abc.com" and "cde.com", both pointing to the same
physical path on the server.
I have a config section in web.config, for example, defines the greeting
message in the web site.

If a client connect to "abc.com", my aspx page will display a message
"Welcome to ABC World".
If a client connect to "cde.com", my aspx page (the same page) will display
the message "Welcome to My second World", for example. (These messages will
not have any relationship with the domain name so we won't simply get the
domain name)

So I just want to define this greeting message in the web.config file and
have it displayed according to different web sites.
Actually there's much more to config and many different pages, so we will
not consider programatically write the logics in the code behinds.

Thanks.

George
 
Actually my problem is how to have different configuration settings if the
application is of one physical folder but just pointed by 2 web sites or
virtual directory.

Here are more details:

1st Website "Default Web Site"
- domain name "abc.com"
- home directory: "C:\MyWebSite"
- web.config: "C:\MyWebSite\web.config"


2nd Website "CDE"
- domain name "cde.com"
- home directory: "C:\MyWebSite"
- web.config: "C:\MyWebSite\web.config"

All the pages under the ASP.NET application uses the same web.config which
is placed at the web root folder. so if I have custom settings for each of
the web site, how can I do it?

Thanks

Best Regards,
George
 
My suggestion is to create your own .config file. For example
<yoursitename>.config and place it in your web directory. For each site you
can have one config file, you write your own logic to read the data from
config file. So site1 reads its data from site1.config file and site2 reads
its data from site2.config. You can place generice data in web.config file.

This might not be a best solution. If you need more information, then get
back to me.
 
Follow Saravana's suggestion about making your config files. It's not
terribly difficult to do (see StreamReader) and makes this a lot
better. As to how to detect the host (abc.com or cde.com), use
Request.Url.Host.

Essentially:

protected class Settings {
public string Name;
};

private Settings mySettings = new Settings();

private void Page_Load(object sender, System.EventArgs e)
{
string fileName;

if (Request.Url.Host == "abc.com")
fileName = "abc.config";
else
fileName = "cde.config";

// Read file and assign Settings as appropriate
}

While not a complete solution, it should be enough to get you started.

James
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top