Adding simple custom schema to IIS Configuration

Let's see if I can get 2 blog posts written in the same month!  :) 

As I was talking last post, our team had an app-building week (everyone will see the results over the next couple months; there were some VERY cool tools that I'm excited for people to see).  I wanted to document part of my journey on getting a custom schema added. 

One thing that I noted is that it's important to make sure your schema file is well-formed XML, or all sorts of tools will choke in various ways. 

I looked at the existing iis_schema.xml for examples of various elements that I could use.   Also, this IIS.net article is extremely helpful in getting started:  http://www.iis.net/articles/view.aspx/IIS7/Extending-IIS7/Extending-IIS7-Configuration/Extending-IIS7-Schema-and-Accessing-the-custom-sec 

I ended up creating this schema:

<configSchema>
  <sectionSchema name="ENC-Pony">
    <attribute name="CanIHaveAPonyPlease" type="bool" defaultValue="false" />
    <attribute name="YesResponse" type="string"  defaultValue="Yes, you can have a pony" />
    <attribute name="NoResponse" type="string"  defaultValue="No, you cannot have a pony" />
    <element name="ponies">
      <collection addElement="add" >
        <attribute name="PonyLocationType" type="enum" defaultValue="AsciiFile">
          <enum name="AsciiFile" value="0" />
          <enum name="ImageFile" value="1" />
          <enum name="HttpLink" value="2" />
        </attribute>
        <attribute name="value" type="string" validationType="nonEmptyString" />
      </collection>
    </element>
  </sectionSchema>
</configSchema>

I wanted to automate adding my custom Section to the IIS config system, so I saw that MVolo has a tool to do just that; it works great.  It's really just adding one line to applicationhost.config, but it's easier said than automated. 

The line that needs to be added to the <configSections> element is:

        <section name="ENC-Pony" overrideModeDefault="Allow" allowDefinition="Everywhere" />

Here is the iisschema.exe tool which will let you add this line item automatically. 

http://mvolo.com/blogs/serverside/archive/2007/08/04/IISSCHEMA.EXE-_2D00_-A-tool-to-register-IIS7-configuration-sections.aspx 
http://www.harbar.net/archive/2007/08/08/IISSCHEMA.EXE--A-tool-to-register-IIS7-configuration-sections.aspx

At this point, I could read and write configuration through tools like appcmd and the rest of the configuration stack (including the UI Configuration Editor module). 

The next post will be how to develop a managed module that runs in the IIS pipeline. 

1 Comment

  • Hey Dave,

    Glad to hear its working for you! Adding the section declaration is really a very simple task, but without an automated way to do it, its a very big nuisance :)

    The cool thing about iisschema.exe is the ability to automatically install the schema file and register ALL of the sections in it in applicationHost.config in a single shot, so you dont need to worry about how to do any of the steps and just get to using your config section.

    iisschema.exe /install myschemafile.xml

    Then you are good to go and use all of the sections you created right away.

    Looking forward to see the module!

    Thanks,

    Mike

Comments have been disabled for this content.