web.config Usage Guide

  • 2021-06-28 12:20:29
  • OfStack

< connectionStrings configSource="db.config"/ >

External file db.config:


<connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-WebApplication1-20140304225906;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-WebApplication1-20140304225906.mdf"
      providerName="System.Data.SqlClient" />
    <add name="ReportServerTempDBConnectionString" connectionString="Data Source=.;Initial Catalog=ReportServerTempDB;Integrated Security=True"
      providerName="System.Data.SqlClient" />
  </connectionStrings>

Specific format

< Node name configSource="Profile path"/ >

Points of Attention

1. If configSource is specified, the node configuration below connectionStrings in web.config will be invalid, even if the connection string node below connectionStrings in web.config has not been deleted.

2. The root node of the external file must be the same as the node specified in web.config (that is, the configuration of the node is moved to the external file)

3.1 nodes can only specify one external profile, and cannot specify one external file for multiple nodes, such as connectionStrings and configSource for appSettings.

Node Data Acquisition

ConfigurationManager.GetSection ("Node Name");//Returns a node object

Imagine: after the installation, ASP.NET5 will be cross-platform, using json as the configuration file, it should also be possible to do the same!

The above is the whole content of this article, I hope you like it.


Related articles: