Call an external file in the web. config file of Asp.net 2.0

Source: Internet
Author: User
Tags connectionstrings

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.