In a work project or work group, it may be necessary to frequently change the debugging environment of the work, such as development environment, test environment, and deployment environment. In this way, it may be necessary to modify or change the web.config file, such as changing the connection character of the database. string, role configuration, security configuration environment, etc. If you are not careful, it is easy to make omissions and other errors. In the web.config file of asp.net 2.0, a new feature that can introduce external files has been added.
This allows us to prepare several files in advance. For example, we can write frequently changed parts, such as database connection strings, etc., into several xml files according to different development environments, and then adjust them as needed in web.config. Come in. For example,
we first create two directories, one called test and one called developer, to store different environments used during testing and development. For example, create a developerconnectionstring.xml in the devloper file, with the following content:
<connectionStrings>
<add name="connstr" connectionString=
"data source=.sqlexpress;initial catalog=
northwind;integrated security=true"
providerName="System.Data.SqlClient"/>
</connectionStrings>
Create another developerappsettingstring.xml as follows <appSettings>
<add key="autoemail" value=" [email protected] /> </appSettings>
Create another developermembership.xml as follows:
<membership defaultProvider="Northwind">
<providers>
<add name="Northwind"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="connstr"/>
</providers>
</membership>
In the same way, you can create a similar xml file in the test directory, and then call it like this in web.config
<?xml version="1.0"?>
<configuration>
<appSettings configSource="developerdeveloperappsettingstring.xml"/>
<connectionStrings
configSource="developerdeveloperconnectionstring.xml" />
<system.web>
<membership
configSource="developerdevelopermembership.xml"/>
<compilation debug="true"/>
<authentication mode="Forms"/>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</configuration>
As you can see, in web.config, the external file
jackyrong BLOG
can be read through the configsource attribute