What suits me best to access settings from config?

I want to know what is best for accessing settings in a configuration file when you have dev / test / production files.

If you have a different configuration for each type, when you publish an ASP.NET website is the config also not copied?

Malcolm

+4
source share
3 answers

Usually we manually enter the settings file on each site. I think it is unusual, although not unheard of, to actually rely on VS to publish on your production site. The control source has dev / test / prod / etc files. Web.config.

+3
source

In Visual Studio 2010, you can support multiple Web.Config and use the transform to create the right configuration for your environment.

http://blogs.msdn.com/webdevtools/archive/2009/05/04/web-deployment-web-config-transformation.aspx

Basically, we can create one default Web.Config and different Transformation files for each environment, for example.

Web.Debug.Config Web.Staging.Config Web.Production.Config

A Transformation file can override the value of a specific configuration item for an environment, for example.

<?xml version="1.0"?> <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> <connectionStrings> <add name="personalDB" connectionString="Server=StagingBox; Database=personal; User Id=admin; password=StagingPersonalPassword" providerName="System.Data.SqlClient" xdt:Transform="Replace" xdt:Locator="Match(name)" /> <add name="professionalDB" connectionString="Server=StagingBox; Database=professional; User Id=professional; password=StagingProfessionalPassword" providerName="System.Data.SqlClient" xdt:Transform="Replace" xdt:Locator="Match(name)"/> </connectionStrings> </configuration> 

Whenever we configure the build for this environment, Transformation is applied to the default Web.Config file.

+1
source

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


All Articles