Multiple ASP.NET Configuration Files

I found several pieces of information about having several ASP.NET configuration files for web deployment. However, I am still not sure if I can accomplish what I want to achieve.

Basically, the website I'm working on can be deployed to three different sites. Depending on the location where it is deployed, you need to change the configuration settings. I would like to have configuration files for each possible configuration (full web.config files), and then I could tell the deployment assembly which configuration file to use for a specific deployment (I can edit this manually if necessary).

Is there something as simple as pointing to another .config file, or do I need to do something more complex?

EDIT: One of the main problems that I have is that I also need settings in the system.net settings for mail, etc. Therefore, I am not looking only to override appSettings.

thank

+3
source share
3 answers

Any section of the configuration, such as <smtp>, can be "internalized," for example. stored in an external file.

Besides the operator file=on <appSettings>(which is available only for application settings :-() it is not an "additional" parameter - you just point your configuration system to an external file.

So you can get this in your app.config / web.config:

  <system.net>
    <mailSettings>
      <smtp configSource="smtp.test.config" />
    </mailSettings>
  </system.net>

smtp.test.config:

<?xml version="1.0" encoding="utf-8" ?>
<smtp>
  <network host="smtp.test.com" port="244" userName="test" password="secret" />
  <specifiedPickupDirectory pickupDirectoryLocation="C:\temp\mails"/>
</smtp>

.NET 2.0 (, 1.x) , , <system.web>.

, , smtp.staging.config .., web.config.

, script, XML .

.NET 4 web.config, , , .

+4

web.config appSettings

<appSettings file="Web.site1.config">

asp.net . web.config, , .

+1

You can do this in the .Net Framework 4. ScottGu demonstrates his quick demo in his recent conversation in Sweden . In his example, he has a statement, production, etc., Moreover, each file has (potentially) different content.

0
source

Source: https://habr.com/ru/post/1728490/


All Articles