Programming Microsoft ASP.NET 4 - Dino Esposito [57]
been further improved with the introduction of routing. You might want to choose the new routing API as your first option in an ASP.NET 4 application. (I’ll cover routing in the next chapter.)
The Section
The section contains only the clientScriptsLocation attribute that specifies the default path to ASP.NET client script files. These files are included in the HTML code generated for .aspx pages when these pages require client-side functionalities such as smart navigation and client-side control validation.
The preceding code snippet represents the default contents of the section. The content of clientScriptsLocation, properly expanded, is the URL used for searching scripts to be included. The aspnet_client directory is automatically created under the Web server’s root when you install ASP.NET. The two placeholders in the string represent subdirectories whose name might change in future versions of ASP.NET. The first placeholder is always set to system_web. The second placeholder expands to a subdirectory name based on the version of the .NET Framework.ASP.NET 4 doesn’t use this folder to store client script files. Client script files are, in fact, embedded as resources in the system.web assembly and are injected in pages through the webresource.axd HTTP handler.
You can use the client script folder to store script files employed by any custom ASP.NET controls you might write.
The Section
The section designates the XHTML rendering mode for an application. The default rendering for pages and controls is XHTML 1.0 Transitional. This is also the default for new pages created in Microsoft Visual Studio 2010. You can configure the preferred rendering by setting options in the section, which enables you to select XHTML 1.0 Transitional, XHTML1.0 Strict, and legacy rendering.
If you opt for Legacy, pages and controls will render as in ASP.NET 1.x.
Other Top-Level Sections
The sections under the element don’t exhaust the list of configuration elements that are useful to ASP.NET developers. At least three other sections should be known and mastered.The Section
The section stores custom application configuration data such as file paths, URLs of interest, or any other application-wide information:
The syntax of the section is defined as follows:
The element adds a new setting to the internal collection. This new setting has a value and is identified by a unique key. The element removes the specified setting from the collection. The setting is identified using the key. Finally, the element clears all settings that have previously been defined in the section.As the name of the section implies, you should store in the section application-specific settings and avoid storing user-specific information. For user-specific information, you can use the user profile API. (See Chapter 8.)
Any contents you design for storage in the section can be saved to an external XML file that is linked to the section through the file attribute:
The content of the file pointed to by the file attribute is read as if it is an section in the web.config file. Note that the root element of the file must match .Note
Changes to the external file are not detected until the application is restarted. If you incorporate in the web.config file, any changes are instead detected in real time.The Section
The section is specifically designed to contain connection strings and is laid out as follows: