IIS snapin extensibility. Part 1.

Configuration schema extensions

IIS configuration is an open system, it easily could be extended by end user through schema extension and through adding extended methods, elements and attributes to existing elements. This is described in great details in other documents and I will just briefly mention it here. When you extend configuration this way, you don't need to do anything in snapin, your data will be immediately accessible through all commands that take section path as a parameter. I will only show, how to do all these steps in PowerShell.

First, you need schema. You could create schema file in any editor, then copy it into %windir%system32\inetsrv\config\schema. Since we are in PowerShell business, we will do it in PowerShell. I will repeat steps from Tobin's article using PowerShell.

$schema = @"
<configSchema> 
  <sectionSchema name="system.webServer/simpleLogging"> 
    <attribute name="logfileDirectory" type="string" 
      defaultValue="%systemdrive%\inetpub\logs\simpleLogs" 
      expanded="true" encrypted="false" /> 
  </sectionSchema>
</configSchema>
"@ 

Now our schema is stored in variable $schema. Let's save it to schema file

new-item (join-path $env:SystemRoot ` 
  'system32\inetsrv\config\schema\simpleLog_schema.xml') ` 
  -type file -value $schema

That's it. We have new section. Before we could use it, we have to declare this section in some configuration file. We will make it globally available.

add-webconfigurationproperty `
   /system.webServer MACHINE/WEBROOT/APPHOST ` 
   -name Sections -value simpleLogging

To check that we have all done correctly, let's get attribute from the section. It should be default value, defined in the schema:

get-webconfigurationproperty `
    /system.webServer/simpleLogging `
    -name logfileDirectory


ItemXPath                   : /system.webServer/simpleLogging
IsInheritedFromDefaultValue : True
IsProtected                 : False
Name                        : logfileDirectory
TypeName                    : System.String
Schema                      : Microsoft.IIs.PowerShell…
Value                       : C:\inetpub\logs\simpleLogs
IsExtended                  : False

We did it! If you will follow Tobin's article, you will find how to schema through COM based method and property. Again, you don't need to do anything in IIS snapin. COM backed methods and attributes will be automatically converted to CodeMethod and CodeProperty on the objects that snapin will produce. You could use these methods and attributes the same way as normal attributes. The only difference is that attributes, backed by COM are 'live', i.e. you will get current value of it each time when you access it. Regular attributes are copies of configuration data.

In the next part I will show you how to extend provider namespace.

--Sergei

No Comments