Service Autostart Providers <serviceAutoStartProviders>

Overview

The <serviceAutoStartProviders> element specifies a collection of managed assemblies that Windows Process Activation Service (WAS) will load automatically when the startMode attribute of an application pool is set to AlwaysRunning. This collection allows developers to specify assemblies that perform initialization tasks before any HTTP requests are serviced. For example, an application developer may want to establish the initial database connections for the application before IIS begins request processing; this will enable the application to perform faster for initial requests that require round trips to and from a database.

For more information about how to configure application pools to start automatically, see the <applicationPools> topic.

Note

This element was introduced in IIS 7.5.

Compatibility

Version Notes
IIS 10.0 The <serviceAutoStartProviders> element was not modified in IIS 10.0.
IIS 8.5 The <serviceAutoStartProviders> element was not modified in IIS 8.5.
IIS 8.0 The <serviceAutoStartProviders> element was not modified in IIS 8.0.
IIS 7.5 The <serviceAutoStartProviders> element was introduced in IIS 7.5.
IIS 7.0 N/A
IIS 6.0 N/A

Setup

The <serviceAutoStartProviders> element is included in the default installation of IIS 7.5.

How To

How to configure a service autostart provider

Note

There is no direct user interface that lets you configure the <serviceAutoStartProviders> element, therefore the following steps will use the IIS Configuration Editor feature.

  1. Open Internet Information Services (IIS) Manager:

    • If you are using Windows Server 2012 or Windows Server 2012 R2:

      • On the taskbar, click Server Manager, click Tools, and then click Internet Information Services (IIS) Manager.
    • If you are using Windows 8 or Windows 8.1:

      • Hold down the Windows key, press the letter X, and then click Control Panel.
      • Click Administrative Tools, and then double-click Internet Information Services (IIS) Manager.
    • If you are using Windows Server 2008 or Windows Server 2008 R2:

      • On the taskbar, click Start, point to Administrative Tools, and then click Internet Information Services (IIS) Manager.
    • If you are using Windows Vista or Windows 7:

      • On the taskbar, click Start, and then click Control Panel.
      • Double-click Administrative Tools, and then double-click Internet Information Services (IIS) Manager.
  2. In the Connections pane, click the server name.

  3. In the Home pane, double-click the Configuration Editor feature.
    Screenshot of Server Home pane displaying Configuration Editor selected.

  4. In the Section drop-down menu, expand system.applicationHost, and then click serviceAutoStartProviders.
    Screenshot of Configuration Editor page showing system dot application Host tab expanded.

  5. Click the ellipsis (...) on the right-side of the (Collection) field.

  6. In the Actions pane, click Add.

  7. When the Collection Editor dialog box appears:

    • Enter the name of your autostart provider in the name field. For example:
      "MyAutostartProvider"
    • Enter the managed type of your autostart assembly in the type field. For example:
      "MyAutostartProvider, MyAutostartProvider, version=1.0.0.0, Culture=neutral, PublicKeyToken=426f62526f636b73"
    • Close the Collection Editor dialog box.
      Screenshot of Collection Editor dialog box showing fields for name and managed type of auto start provider.
  8. In the Actions pane, click Apply.

Note

This section contains information about how to modify your IIS settings by using the IIS Configuration Editor. Incorrectly editing your IIS configuration settings can severely damage your IIS installation. Therefore, make sure that you follow these steps carefully. For added security, you should back up your IIS configuration settings before you use the IIS Configuration Editor to make any modifications. For more information about how to back up your IIS configuration settings and how to use the IIS Configuration Editor, see the following topics:

Configuration

The <serviceAutoStartProviders> element is configured at the global level in the ApplicationHost.config file.

Attributes

None.

Child Elements

Element Description
add Optional element.

Adds a provider to the collection of autostart providers.
clear Optional element.

Clears the collection of autostart providers.
remove Optional element.

Removes a provider from the collection of autostart providers.

Configuration Sample

The following sample displays a <serviceAutoStartProviders> element that adds a custom autostart provider to the collection.

<serviceAutoStartProviders>
   <add name="MyAutostartProvider" type="MyAutostartProvider, MyAutostartProvider, version=1.0.0.0, Culture=neutral, PublicKeyToken=426f62526f636b73" />
</serviceAutoStartProviders>

Sample Code

The following examples add a sample provider to the collection of autostart providers.

AppCmd.exe

appcmd.exe set config -section:system.applicationHost/serviceAutoStartProviders /+"[name='MyAutostartProvider',type='MyAutostartProvider, MyAutostartProvider, version=1.0.0.0, Culture=neutral, PublicKeyToken=426f62526f636b73']" /commit:apphost

Note

You must be sure to set the commit parameter to apphost when you use AppCmd.exe to configure these settings. This commits the configuration settings to the appropriate location section in the ApplicationHost.config file.

C#

using System;
using System.Text;
using Microsoft.Web.Administration;

internal static class Sample {
   private static void Main() {
      using(ServerManager serverManager = new ServerManager()) { 
         Configuration config = serverManager.GetApplicationHostConfiguration();
         ConfigurationSection serviceAutoStartProvidersSection = config.GetSection("system.applicationHost/serviceAutoStartProviders");
         ConfigurationElementCollection serviceAutoStartProvidersCollection = serviceAutoStartProvidersSection.GetCollection();

         ConfigurationElement addElement = serviceAutoStartProvidersCollection.CreateElement("add");
         addElement["name"] = @"MyAutostartProvider";
         addElement["type"] = @"MyAutostartProvider, MyAutostartProvider, version=1.0.0.0, Culture=neutral, PublicKeyToken=426f62526f636b73";
         serviceAutoStartProvidersCollection.Add(addElement);

         serverManager.CommitChanges();
      }
   }
}

VB.NET

Imports System
Imports System.Text
Imports Microsoft.Web.Administration

Module Sample
   Sub Main()
      Dim serverManager As ServerManager = New ServerManager
      Dim config As Configuration = serverManager.GetApplicationHostConfiguration
      Dim serviceAutoStartProvidersSection As ConfigurationSection = config.GetSection("system.applicationHost/serviceAutoStartProviders")
      Dim serviceAutoStartProvidersCollection As ConfigurationElementCollection = serviceAutoStartProvidersSection.GetCollection

      Dim addElement As ConfigurationElement = serviceAutoStartProvidersCollection.CreateElement("add")
      addElement("name") = "MyAutostartProvider"
      addElement("type") = "MyAutostartProvider, MyAutostartProvider, version=1.0.0.0, Culture=neutral, PublicKeyToken=426f62526f636b73"
      serviceAutoStartProvidersCollection.Add(addElement)

      serverManager.CommitChanges()
   End Sub
End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";

var serviceAutoStartProvidersSection = adminManager.GetAdminSection("system.applicationHost/serviceAutoStartProviders", "MACHINE/WEBROOT/APPHOST");
var serviceAutoStartProvidersCollection = serviceAutoStartProvidersSection.Collection;

var addElement = serviceAutoStartProvidersCollection.CreateNewElement("add");
addElement.Properties.Item("name").Value = "MyAutostartProvider";
addElement.Properties.Item("type").Value = "MyAutostartProvider, MyAutostartProvider, version=1.0.0.0, Culture=neutral, PublicKeyToken=426f62526f636b73";
serviceAutoStartProvidersCollection.AddElement(addElement);

adminManager.CommitChanges();

VBScript

Set adminManager = createObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"

Set serviceAutoStartProvidersSection = adminManager.GetAdminSection("system.applicationHost/serviceAutoStartProviders", "MACHINE/WEBROOT/APPHOST")
Set serviceAutoStartProvidersCollection = serviceAutoStartProvidersSection.Collection

Set addElement = serviceAutoStartProvidersCollection.CreateNewElement("add")
addElement.Properties.Item("name").Value = "MyAutostartProvider"
addElement.Properties.Item("type").Value = "MyAutostartProvider, MyAutostartProvider, version=1.0.0.0, Culture=neutral, PublicKeyToken=426f62526f636b73"
serviceAutoStartProvidersCollection.AddElement(addElement)

adminManager.CommitChanges()