In a work project or group, it is often necessary to change the debugging environment of the work, such as the development environment, test environment, and deployment environment. modify or modify the config file, such as the database connection string, role configuration, and Security Configuration environment. If you are not careful, errors such as omissions may occur. in Asp.net 2.0. in the config file, new features that can introduce external files are added,
So that we can create several files in advance, such as writing several XML files based on different development environments for frequently-modified parts, such as database connection strings, then in the web. config. for example
We first create two directories: Test and developer, respectively, to store different environments used for testing and development, such
Create a developerconnectionstring. xml file in the devloper file. The content is as follows:
<Connectionstrings>
<Add name = "connstr" connectionstring =
"Data Source =. sqlexpress; initial catalog =
Northwind; Integrated Security = true"
Providername = "system. Data. sqlclient"/>
</Connectionstrings>
Create another developerappsetingstring. XML as follows <appsettings>
<Add key = "autoemail" value = "abc@abc.com/> </appsettings>
Create another external membership. XML as follows:
<Membership defaultprovider = "northwind">
<Providers>
<Add name = "northwind"
Type = "system. Web. Security. sqlmembershipprovider"
Connectionstringname = "connstr"/>
</Providers>
</Membership>
Similarly, you can create an XML file similar to the test directory. Then, in Web. config, you can call
<? XML version = "1.0"?>
<Configuration>
<Maid configsource = "Maid maid string. xml"/>
<Connectionstrings
Configsource = "developerdeveloperconnectionstring. xml"/>
<System. Web>
<Membership
Configsource = "zookeeper membership. xml"/>
<Compilation DEBUG = "true"/>
<Authentication mode = "forms"/>
<Authorization>
<Deny users = "? "/>
</Authorization>
</System. Web>
</Configuration>
You can see that in Web. config, you can use the configsource attribute to read external files.