In IIS 7 we introduced a completely new configuration system which is used by the IIS runtime and all our administration tools. The configuration system is based on distributed XML files that contain the configuration for IIS, ASP.NET and other components; flexibility in the configuration system also allows for configuration to be set at a a number of levels including at the server, the site and the application level. Configuration at the site and application level coexists alongside ASP.NET configuration in web.config files.
One of my favourite and in my opinion one of the coolest features of our new config system is that the configuration system itself is extensible. You can quickly and easily extend config with your own attributes, collections, etc. and in fact we use config system extensibility on some of the downloadable modules we ship (e.g. FTP 7.0, and some more to come in the near future... you'll see them on IIS.NET in the next few days)
What do I mean by extensible?
Well, the config system is XML based and configuration definition exists in schema files which are located at %windir%\system32\inetsrv\config\schema. You can go there and look at the IIS_schema.xml file to see the schema definition of the IIS 7 config system. (As a side note, looking at the pre-installed files in the schema directory is a great way to learn more about configuration options in IIS 7.)
So, by extensibility I mean you have the ability to extend configuration with your own schema and get the full usage of the IIS 7 configuration APIs automatically. You can create new configuration sections, extend existing sections and you can even have configuration which is backed by a COM components...
Which begs the question... why?
Simple answer: Open up rscaext.xml and have a look there - we extended our own configuration system to provide additional functionality for you.
If you Install FTP 7 (download here[^] - note that you'll have to remove FTP 6 if it's installed) and then look at the new schema file it adds you'll see that we extend existing configuration sections and add news ones... the FTP runtime can make use of one of the plethora of ways to interact with the config system (appcmd.exe, native config API, managed config api, etc.) There was no need to build a new config system or manually parse XML files.
Adding a new config section
Ok, so lets add a new config section - in this case, a very contrived one. We're going to add a new configuration section under system.webServer called Ireland with an attribute called nationalHoliday.
Note: do not do this on a production environment - you should never, ever, ever play around with extending configuration on a system that is in production use!
- In the %windir%\system32\inetsrv\config\schema directory, create a file called ireland.xml
- Add the following to the file:
<attribute name="nationalHoliday" type="string" />
Next, we need to register our new configuration section so that the configuration system will recognize the schema as being valid and in use.
- Open the primary IIS configuration file, %windir%\system32\inetsrv\config\applicationHost.config.
- Look for the <configSections> section and add to <section name="ireland"/> under the system.webServer sectionGroup. You should have something like:
That's it. Configuration has been extended. So, let's test it. Run the following command at the command line:
You should get output of:
Now, let's set the national holiday for the Default Web Site - just run:
appcmd set config "Default Web Site" -section:system.webServer/ireland /nationalHoliday:"St. Patricks Day"
Now, let's check the config for default web site:
%windir%\system32\inetsrv\appcmd list config "Default Web Site" -section:system.webServer/ireland
You're output should be something like:
<ireland nationalHoliday="St. Patricks Day" />
Wohoo!!! We've just extended config with a very contrived example. You could now read that configuration using all of the config system APIs.
More On Extensibility
This was a very short example of how to do basic extensibility. I'll be posting a few more entries about config system extensibility over the next few days and I'll cover extending existing sections, extending config with code (including adding configuration 'methods') and a few other things.
In the mean time, have a read of this Config System Extensibility article I published a while back: http://learn.iis.net/page.aspx/241/configuration-extensibility/