ASP.NET 2.0 provides enhanced support for accessing configuration settings from a configuration file through the new class called System.Web.Configuration.WebConfigurationManager, which pro- vides seamless access to configuration files and configuration sections. This new class renders obsolete the ASP.NET 1.x class ConfigurationSettings that was utilized to access configuration settings from a configuration file. The functionality provided by the methods of this class fall into any of the following three categories. |
Easy and quick access to the configuration sections such as appSettings and |
connectionStrings sections through the use of properties such as AppSettings and |
ConnectionStrings |
Quick access to specific configuration sections of the configuration files through methods such |
as GetSection(), and GetWebApplicationSection() |
Ability to open the specified configuration files using methods such as |
OpenMappedWebConfiguration(), OpenWebConfiguration() and so on |
More information on how to utilize this new class is provided in Chapter 14. |
Benefits of ASP.NET Configuration System |
The XML based ASP.NET configuration system features an extensible infrastructure that not only enables you to define configuration settings at the time of deploying your ASP.NET applications but also allows you to add or revise configuration settings at any time with minimal impact to the operational Web application. The ASP.NET configuration system provides the following benefits: |
The hierarchical configuration architecture provides a flexible and rich configuration system |
that enables extensible configuration settings to be defined and used throughout the ASP.NET applications. |
The configuration information for the ASP.NET applications is stored in plain XML-based config- |
uration files, which makes it easy to read and write. Administrators and developers can use a standard text editor such as Notepad for updating of the configuration settings of the application. |
Because the configuration files are stored in the same directory tree as the rest of the application |
files, the configuration files can be easily deployed along with the rest of ASP.NET application. |
The configuration system is highly flexible and allows developers to create new configuration |
sections, and store customized configuration criteria and settings in the configuration system. This extensibility feature can then be used at runtime to affect the processing of the HTTP requests. |
The configuration system allows the automation of any configuration updates made to the ASP. |
NET configuration files meaning that whenever changes are made to a configuration file, the application can pick up the new changes instantaneously without requiring user intervention. |
The configuration information contained in the XML file is applied hierarchically with regard to |
the virtual directory structure, which is provided at the time of Web site creation. Subdirectories under the virtual directory inherit or override the configuration settings from their parent direc- tories. This allows different settings for different applications or for different parts of a single application. |
Now with the introduction of the new WebConfigurationManager class, you can programmat- |
ically interact with the different sections in the configuration files such as Web.config, machine.config with minimal effort. |
XML Classes in the .NET Framework |
Summary |
This chapter introduced the basic concepts of XML in .NET Framework, and provided a concise overview of the .NET classes available to read, store, and manipulate XML documents. The System.Xml namespaces contain probably the richest collection of XML-related classes available thus far in any other software development platform. The XML support in .NET Framework 2.0 has been further enriched by the recent addition of XslCompiledTransform class that provides improved functionality and performance enhancements. To summarize this chapter: |
The System.Xml namespace provides the XmlReader and XmlWriter classes that enable you |
to parse and write XML data from streams or XML documents. |
The XmlReader class enables you to access XML data from a stream or XML document. This |
class provides fast, non-cacheable, read-only, and forward-only access to XML data. |
The XmlWriter class is the core class that enables you to create XML streams and write data in |
well-formed XML documents. You use XmlWriter to perform tasks such as writing multiple documents into one output stream, writing valid names and tokens into the stream, encoding binary data and writing text output, managing output, and flushing and closing the output stream. |
The XmlDocument class is a representation of the XML document in memory. The XmlDocument |
class allows you to read, write, and manipulate an XML document. The DOM includes a set of libraries that contain classes, which enable you to navigate through an XML document and obtain relevant information. Every XML document consists of parent and child nodes. |
In an XML document, you use XPath to access a node or a set of nodes. The XPathNavigator |
class of the .NET Framework contains the methods that you use to perform XPath queries on an XML document. XPath support in .NET Framework 2.0 is enhanced by the editing support added to the XPathNavigator. |
The structure of valid XML documents is specified by XSD files. You can ensure the validation |
of XML documents by using the XmlReaderSettings class. The XmlReaderSettings class in conjunction with the XmlSchemaSet class provides the DTD, and XSD schema validation services that enable you to validate an XML document or a fragment of an XML document. |
The SOM consists of a set of classes that enable you to read the schema definition from a file. In |
addition, you can use the classes in the SOM to create the schema definition files programmatically. These SOM classes are part of the System.Xml.Schema namespace. |
When you load an XML document into a DataSet, XML schema validates the data that is |
fetched from the XML document. The XML schema contains all the information about the relational structure, such as tables, constraints, and relations that are necessary to validate an XML document. |