Saturday, November 7, 2009

Configuration Files

Configuration Files
Configuration files are XML files that can be changed as needed. Developers can use configuration files to change settings without recompiling applications. Administrators can use configuration files to set policies that affect how applications run on their computers.
Note Managed code can use the System.Configuration API to read settings from the configuration files, but not to write settings to those files.
This section describes the syntax of configuration files and provides information about the three types of configuration files: machine, application, and security.

Configuration File Format
Briefly describes the format of configuration files.
Machine Configuration Files
Describes the contents of machine configuration files.
Application Configuration Files
Describes the different types of application configuration files.
Security Configuration Files
Provides the location of the security configuration files.

Configuration File Format
Configuration files contain elements, which are logical data structures that set configuration information. Within a configuration file, you use tags to mark the beginning and end of an element. For example, the element consists of child elements. An empty element has a start tag, but no end tag.
You specify configuration settings using predefined attributes, which are name/value pairs inside an element's start tag. The following example specifies two attributes (version and href) for the element, which specifies where the runtime can locate an assembly (for more information, see Specifying an Assembly's Location).


The syntax in configuration files is case-sensitive.

Machine Configuration Files
The machine configuration file, Machine.config, contains settings that apply to an entire computer. This file is located in the %runtime install path%\Config directory. Machine.config contains configuration settings for machine-wide assembly binding, built-in remoting channels, and ASP.NET.
The configuration system first looks in the machine configuration file for the element and other configuration sections that a developer might define. It then looks in the application configuration file. To keep the machine configuration file manageable, it is best to put these settings in the application configuration file. However, putting the settings in the machine configuration file can make your system more maintainable. For example, if you have a third-party component that both your client and server application uses, it is easier to put the settings for that component in one place. In this case, the machine configuration file is the appropriate place for the settings, so you don't have the same settings in two different files.
Note Deploying an application using XCOPY will not copy the settings in the machine configuration file.

Application Configuration Files
Application configuration files contain settings specific to an application. This file contains configuration settings that the common language runtime reads (such as assembly binding policy, remoting objects, and so on), and settings that the application can read.
The name and location of the application configuration file depend on the application's host, which can be one of the following:
Executable–hosted application.
The configuration file for an application hosted by the executable host is in the same directory as the application. The name of the configuration file is the name of the application with a .config extension. For example, an application called myApp.exe can be associated with a configuration file called myApp.exe.config.
ASP.NET-hosted application.
ASP.NET configuration files are called Web.config. Configuration files in ASP.NET applications inherit the settings of configuration files in the URL path. For example, given the URL www.microsoft.com/aaa/bbb, where www.microsoft.com/aaa is the Web application, the configuration file associated with the application is located at www.microsoft.com/aaa. ASP.NET pages that are in the subdirectory /bbb use both the settings that are in the configuration file at the application level and the settings in the configuration file that is in /bbb.
For more information about ASP.NET configuration files, see ASP.NET Configuration
Internet Explorer-hosted application.
If an application hosted in Internet Explorer has a configuration file, the location of this file is specified in a tag with the following syntax:

In this tag, location is a URL to the configuration file. This sets the application base. The configuration file must be located on the same Web site as the application.

Security Configuration Files
Security configuration files contain information about the code group hierarchy and permission sets associated with a policy level. It is strongly recommended that you use the .NET Framework Configuration tool (Mscorcfg.msc) or Code Access Security Policy tool (Caspol.exe) to modify security policy to ensure that policy changes do not corrupt the security configuration files.
The following table shows the locations of the security configuration files.






No comments:

Post a Comment