The Management API has been integrated into the IIS Management Console, so when you view the properties of a site or virtual directory, you now see an additional ASP.NET tab, as shown in Figure 13.4. Figure 13.4. IIS ASP.NET configuration
On this screen you can see the current ASP.NET version, with a drop-down list allowing you to select other versions to use for this application (if other versions are installed). You can also see the full path to the application and the dates and times the configuration file was created and changed. Figure 13.5 shows the screen that appears when the Edit configuration button is selected. Here you can see tabs for the major configuration sections. We won't go through them in detail because they just map the properties from the XML file. Any settings that don't appear to have a tab themselves are on other tabsMembership and Roles are on the Authentication tab, and things like Tracing, Compilation, HTTP Handlers, and so on are on the Advanced tab. Figure 13.5. ASP.NET Configuration Settings window
There are two things to note about this interface.
Management ClassesThe management classes reside in the System.Web.Management and System.Configuration namespaces. There are too many classes to detail here, but essentially each class provides a strongly typed interface to a configuration section, with properties representing the individual attributes of the XML file. For example, listed below are a couple of the classes.
The Configuration class provides access via properties to the various sections. For example: Dim server As WebApplicationServer Dim cfg As System.Configuration.Configuration server = WebApplicationServer.OpenServer("localhost") cfg = System.Configuration.Configuration.GetConfigurationForUrln("App") At this stage cfg contains references to the configuration details for the selected application, and these are accessed via properties such as Web (for the system.web section) and AppSettings (for the appSettings section). The configuration details are a merge of all settings from the current node back up the hierarchy. Updating Configuration SettingsTo update settings you simply use a property. For example, it would be possible to turn off custom errors with the following lines of code: cfg.Web.CustomErrors.Mode = CustomErrorsMode.Off cfg.Update() Updates are always written back to the currently open node and cannot be written to a node higher up. However, before writing settings, you need to ensure that you are allowed to do so because the section might be locked. Check the IsLocked property: If Not cfg.Web.CustomErrors.IsLocked Then cfg.Web.CustomErrors.Mode = CustomErrorsMode.Off cfg.Update() End If
|