Store. NET application to a custom XML. config file

Source: Internet
Author: User
Tags config configuration settings key sql net web services
xml| Program

In the decision distribution is based. NET Framework, you decide how to manage the settings for your public programs. To improve code reuse and application interoperability, all application –web, Windows, WEB services, and Windows services use the application configuration file as a public way to manage application-centric information.

System configuration vs. application configuration
When the. NET's common language runtime (CLR) executes the application, it uses a series of XML configuration files to set the basic properties of the running environment. For example, if you execute a Web application, the CLR asks the Web.config file to determine the following settings, including authentication mode (Forms, Windows, or none), authenticated Users, session state settings (InProc, StateServer, or SQL), as well as other key settings.
As above, the Machine.config system file provides the ASP.net configuration settings for the entire site and sets the base settings for the web.config for ASP.net applications. Security.config and Enterprisesec.config define system-wide security and code permission settings that apply to Windows applications.
If your application needs to run in the same running environment, the default settings will meet your needs and run well. However, if a specific configuration is required to be provided to an application-based application, you can store that information in a specific CLR-approved file and invoked by the application.

Store application configuration information
. NET application is stored in the directory where the application executes, with. config as the file name extension. The full file name of the application can be used as the prefix name for the configuration file:
Applicationname.exe.config
< can also obtain application settings programmatically from Xml.config files using the System.Configuration namespace. The following example application configuration file shows the connection string stored in the application.

<configuration>
<appSettings>
<add key= "ConnectionString" value= "Provider=SQLOLEDB.1 ..."/>
</appSettings>
</configuration>

Store application configuration information to an external file to update the application's properties without recompiling the entire program. For example, suppose you are developing an application based on an SQL database, if you write the connection information inside the program. When the database is transferred to another server, the program needs to be recompiled and redistributed to accommodate the change. If you use a. config file, the only thing to do is to change the ConnectionString key in the. config file.

To use the. config file more effectively, you need to create a standard definition of key names and values for the application that will be the standard for the entire development team, which allows developers working on the same project to use the same project settings. This standard is also useful when distributing applications and delivering production. Once the. config setting is standardized, the operations team will know where to start checking and scheduling problems when a common application configuration issue occurs.



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.