IIS7 Managed Extensibility: Deployment

OK – let’s face it – deployment is no fun. The fact that in addition APIs are fragmented, inconsistent or simply missing doesn’t make it more entertaining. But here are the general steps that are necessary to deploy an IIS7 feature.

Register all assemblies in the GAC
See my previous post for more details.

Register the configuration extension
This is a two step process – first you have to copy the schema file to the schema directory

%SystemDrive%%windir%system32inetsrvconfigschema

The next step is to register the section in the <configSections> element in applicationHost.config. Unfortunately there is no API to do that currently (but will be available in “Longhorn Server” starting with Beta 3). So XmlDocument is your friend….

private void RegisterApplicationHost()

{

    XmlDocument doc = new XmlDocument();

    doc.Load(_applicationHost);

 

    XmlNode node = doc.SelectSingleNode(

      “configuration/configSections/sectionGroup[@name=’system.webServer’]”);

 

    XmlElement configNode = doc.CreateElement(“section”);

    configNode.SetAttribute(“name”, _configSectionName);

    configNode.SetAttribute(“overrideModeDefault”, “Allow”);

 

    node.AppendChild(configNode);

 

    doc.Save(_applicationHost);

}

The resulting section looks like this.

<sectionGroup name=system.webServer>

  <section name=serverHeader overrideModeDefault=Allow />

 

Register the HttpModule
The HttpModule can be registered in applicationHost.config if you want it to be available machine wide. Otherwise you would register it in a down-level web.config. The following code uses the ServerManager class in Microsoft.Web.Administration to access applicationHost.config and to add the module:

private void RegisterHttpModule()

{

    ServerManager manager = new ServerManager();

 

    // get access to applicationHost.config

    Configuration config = manager.GetApplicationHostConfiguration();

 

    // install the module

    ModulesSection sectionModules = (ModulesSection)

        config.GetSection(ModulesSection.SectionName, typeof(ModulesSection));

 

    sectionModules.Modules.Add(_httpModuleName,

        _httpModuleType,

        “”);

 

    manager.CommitChanges();

}

The result should look like this:

<system.webServer>

  <modules>

    <add name=ServerHeaderModule

         type=LeastPrivilege.ServerHeader.ServerHeaderModule, … ” />

  </modules>

</system.webServer>

Register the Management Extension
The last step is to add a reference to the ServerHeader module provider to administration.config. Again ServerManager can be used to access this configuration file (this time using the GetManagementConfiguration() method). The code is very similar to the previous one so I will omit this here.

The result should look like this:

<moduleProviders>

  <add name=ServerHeader type=“… “ />

 

 

<location path=.>

  <modules>

    <add name=ServerHeader />

The above procedures can be e.g. used in a VS installer project (using custom actions).

Next Post: the complete solution (finally)…

 

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s