IIS Integration

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

graphics/13fig04.gif

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

graphics/13fig05.gif

There are two things to note about this interface.

  • It shows a merged view of the settings and thus includes settings from all levels of the hierarchy.

  • Sections can be locked, thus preventing any changes at a lower level in the application hierarchy. When locking a section is allowed, you'll see a padlock icon next to the section.

Management Classes

The 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.

  • WebApplicationServer maps to a Web server.

  • Configuration maps to the configuration file.

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 Settings

To 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 

Note that the ASP.NET process needs write permissions on both the web.config file and the application directory. This is because a copy of web.config is created during the update process and removed once the update is complete.



A First Look at ASP. NET v. 2.0 2003
A First Look at ASP. NET v. 2.0 2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 90

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net