38.1. Config Files

The .NET Framework configuration system consists of several configuration files (discussed in the sections) that can be used to adjust one or more applications on a computer system. Part of this system is an inheritance model that ensures that configurations can be applied at the appropriate level.

38.1.1. Machine.Config

At the root of the inheritance model is the machine.config file (located in the systemrootMicrosoft .NETFrameworkversionNumberCONFIG folder), which defines configuration settings for the entire system. All configuration files inherit from this file and can override these settings. It is worth noting that although Visual Studio 2008 ships with version 3.5 of the .NET Framework, it is still based on version 2.0 of the CLR, which means that the configuration files are located in a v2.x.x.x sub-folder.

38.1.2. Web.Config

Web applications are configured via the web.config file. This file can be located in a number of locations, depending on the scope to which the settings need to be applied. To apply a configuration to all web applications on a machine, place the web.config file in the same directory as the machine.config file. In most cases the settings need to be applied at a much finer granularity. As such, the web.config file can also be placed in any virtual directory or subdirectory to control web applications at that level. If it is placed in the root folder for a web site, the configuration will be applied to all ASP.NET applications in that web site.

A word of caution: When you are working with virtual directories that do not align with the directory structure on the computer, it's possible to have an application that has different configurations depending on how it is referenced. For example, consider C:inetpubwwwrootMainApplicationContactsContact.aspx, which has been set up with both MainApplication and Contacts as virtual directories. You can reference the contact page as either:

http://localhost/MainApplication/Contacts/Contact.aspx

or:

http://localhost/Contacts/Contact.aspx

In the first case, the configuration settings that are applied are inherited from the MainApplication folder and may be overridden by a configuration file in the Contacts folder. However, in the second case, settings are applied only from the configuration file within the Contacts folder.

Making changes to a web.config file will cause the ASP.NET application to be restarted. This is quite an effective way to force a web application to flush its cache and behave as if it were being accessed for the first time, without having to restart the entire server.

38.1.3. App.Config

Windows applications can be configured via an application configuration file, which also inherits from machine.config. As the output assembly name is known only when an application is compiled, this file starts off as app.config and is renamed to application.exe.config as part of the build process. For example, an application with AccountingApplication.exe as the main executable would have a configuration file entitled AccountingApplication.exe.config. This configuration file is automatically loaded based on its name when the application is loaded.

38.1.4. Security.Config

In conjunction with the application configuration files are a number of security configuration files. These also follow an inheritance path but across a different dimension. Instead of being application-focused, the security configuration files are broken down into enterprise (Enterprisesec.config), machine (Security.config), and user (Security.config). The enterprise- and machine-level files are both stored in the same location as the Machine.config file, while the user-level file is stored under the user-specific application data folder.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.232.189