In my last post[^] I gave a quick overview of how to extend configuration. More specifically I covered extending configuration by adding new sections to configuration. One thing I also mentioned was that you can extending existing configuration sections too - that's what this post is about.
Extending the "sites" section
To show how to extend existing configuration I'm going to add two new attributes which are configurable for sites. We're going to an an owner and an ownerEmail attribute (a slightly less contrived example than the last post :-)
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 extendExisting.xml
- Add the following to the file:
<attribute name="owner" type="string" />
<attribute name="ownerEmail" type="string" />
Ok, that's it - we've extended schema. Just remember, when extending the schema of an existing section, simply create a <sectionSchema> element and set the name attribute to be the same as an existing section. In the schema file above, we have defined a <sectionSchema> with a name of system.applicationHost/sites - this is the same as the sectionSchema name in the IIS_Schema.xml file in the Schema directory.
Testing the new attributes
Let's do a quick test to see if our new attributes are working. Run the following command to add an owner and ownerEmail to the "Default Web Site":
%windir%\system32\inetsrv\appcmd set site "Default Web Site" /owner:"Master Chief" /ownerEmail:"email@example.com"
You can quickly check to see if the configuration has been applied by running the following:
%windir%\system32\inetsrv\appcmd list site "Default Web Site" /config
Your output should look something like the following:
<site name="Default Web Site" id="1" siteOwner="Master Chief" siteOwnerEmail="firstname.lastname@example.org"></site>
More On Extensibility
This was a very short example of how to extend existing configuration sections. I'll be posting a few more entries about config system extensibility over the next few days and I'll cover extending config with code (including adding configuration 'methods') and a few other things.
My last post, IIS 7 Configuration: Basic Configuration Extensibility[^], covered the basics of configuration extensibility.
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/