Online Book Reader

Home Category

Programming Microsoft ASP.NET 4 - Dino Esposito [36]

By Root 5286 0

Value

Description

Everywhere

The section can be used in any configuration file. (Default.)

MachineOnly

The section can be used only in the machine.config file.

MachineToApplication

The section can be used in the machine.config file and in the application’s web.config file. You cannot use the section in web.config files located in subdirectories of the virtual folder.

The allowLocation attribute determines whether the section can be used within the section. The section in a machine.config file allows you to apply the specified machine-wide settings only to the resources below a given path. (I’ll say more about the section shortly.)

Many sections in the configuration files support three special elements, named , , and . The element adds a new setting to the specified section, while removes the specified one. The element clears all the settings that have previously been defined in the section. The and elements are particularly useful in ASP.NET configuration files in which a hierarchy of files can be created. For example, you can use the element in a child web.config file to remove settings that were defined at a higher level in the configuration file hierarchy.

The and elements don’t affect the actual data stored in the configuration file. Removing a section doesn’t erase the related data from the file, it simply removes the data from the in-memory tree of settings that ASP.NET builds and maintains for an application.

Note

Sections are a necessary syntax element in configuration files. However, you don’t need to declare sections in all application-specific web.config files. When processing a web.config file, in fact, ASP.NET builds a configuration tree starting from the root machine.config file. Because all standard sections are already declared in the machine.config file that ships with the .NET Framework, your application needs to declare only custom sections you plan to use. Finally, bear in mind that an exception is thrown if a configuration section lacks a corresponding entry in the section and when the layout of the data does not match the declaration.

Let’s start our tour of the configuration schema with a closer look at the section.

The Section


The section serves one main purpose in two distinct scenarios. The section provides an alternative technique to apply different settings to various parts of an application. You typically employ the section to apply different settings to subdirectories of the same application and to configure distinct applications installed on the same machine.

When defined inside an application’s root web.config file, it allows you to apply different settings to different subdirectories. Instead of defining child web.config files, you can create a single web.config file in the root folder and specify settings on a per-directory basis. Basically, the element lets you create embedded configuration sections associated with a particular directory. From a functional point of view, this is equivalent to having a web.config file in each directory.

When defined inside the machine.config file, or in a site’s root web.config file, the section enables you to specify different machine-wide settings for various Web applications. Used in this way, the section turns out to be an extremely powerful tool to let multiple applications apply individual machine-wide settings in an ISP scenario.

Important

Note the difference between the application’s root web.config file and the site’s root web.config file. The application’s root configuration file is the web.config file you find in the application’s root folder. You use this file to adapt ASP.NET settings to the needs of the particular application and its subdirectories. In contrast, the site’s root web.config file is located in the same folder as machine.config, and therefore is well outside the Web space of any deployed applications.

Return Main Page Previous Page Next Page

®Online Book Reader