Adding Initialization Page <add>
Overview
The <add>
element under the <applicationInitialization>
element specifies the application to be initialized upon application restart. To perform the application initialization process, IIS sends a fake request to the application to prompt the initialization. Multiple application URLs can be specified by using multiple <add>
tags. These applications are not served to a requester. The page specified by the remapManagedRequestsTo attribute in the <applicationInitialization>
element will be served to the customer.
Compatibility
Version | Notes |
---|---|
IIS 10.0 | The <add> element was not modified in IIS 10.0. |
IIS 8.5 | The <add> element was not modified in IIS 8.5. |
IIS 8.0 | The <add> element was introduced in IIS 8.0. |
IIS 7.5 | N/A |
IIS 7.0 | N/A |
IIS 6.0 | N/A |
Setup
To support application initialization on your Web server, you must install the Application Initialization role or feature.
Windows Server 2012 or Windows Server 2012 R2
- On the taskbar, click Server Manager.
- In Server Manager, click the Manage menu, and then click Add Roles and Features.
- In the Add Roles and Features wizard, click Next. Select the installation type and click Next. Select the destination server and click Next.
- On the Server Roles page, expand Web Server (IIS), expand Web Server, expand Application Development, and then select Application Initialization. Click Next.
. - On the Select Features page, click Next.
- On the Confirm installation selections page, click Install.
- On the Results page, click Close.
Windows 8 or Windows 8.1
- On the Start screen, move the pointer all the way to the lower left corner, right-click the Start button, and then click Control Panel.
- In Control Panel, click Programs and Features, and then click Turn Windows features on or off.
- Expand Internet Information Services, expand World Wide Web Services, expand Application Development Features, and then select Application Initialization.
- Click OK.
- Click Close.
How To
How to configure application initialization
Open Internet Information Services (IIS) Manager:
If you are using Windows Server 2012 or later:
- On the taskbar, click Server Manager, click Tools, and then click Internet Information Services (IIS) Manager.
If you are using Windows 8 or later:
- 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.
In the Connections pane, select the server, or expand the server, expand Sites, and then select a site.
In the Home pane, double-click the Configuration Editor feature.
If you selected a site, select <site name> Web.config in the From text box, and then select system.webServer/applicationInitialization in the Section text box.
If you selected the server, select system.webServer/applicationInitialization in the Section text box.
To specify the name of a static file to be returned during initialization, set remapManagedRequestsTo to the name of the file.
If you do not want to load managed modules, set skipManagedModules to true.
To specify that the initialization process is initiated automatically whenever an application restart occurs, set doAppInitAfterRestart to true.
To specify the application or applications to be initialized upon application restart, click the (Collection) line and then click the ellipsis.
In the Collection Editor, to add an application to be initialized, click Add, click hostName, and then set hostName to the name of the host. Click initializationPage and set it to a URL for the application. Close the dialog box.
Click Apply in the Actions pane.
Configuration
The <add>
element of the <applicationInitialization>
element is configured at the server, site, or application level.
Attributes
Attribute | Description |
---|---|
initializationPage |
Required string attribute. Specifies the URL of an application to be initialized upon application restart. The default value is "" . |
hostName |
Optional string attribute. A host name to be used with the application URL provided in the initializationPage attribute. The default value is "" . |
Child Elements
None.
Configuration Sample
The following sample shows configuration of application initialization.
<system.webServer>
<applicationInitialization
doAppInitAfterRestart="true"
skipManagedModules="true"
remapManagedRequestsTo="filename.htm"/>
<add initializationPage="/default.aspx" hostName="myhost"/>
</applicationInitialization>
</system.webServer>
Sample Code
The following examples configure <applicationInitialization> for a site.
AppCmd.exe
appcmd.exe set config "Default Web Site" -section:system.webServer/applicationInitialization /remapManagedRequestsTo:"HelloJoe.htm" /skipManagedModules:"True" /doAppInitAfterRestart:"True" /commit:apphost
appcmd.exe set config "Default Web Site" -section:system.webServer/applicationInitialization /+"[initializationPage='JoesSite.htm',hostName='JoesHost']" /commit:apphost
Note
You must be sure to set the commit parameter to apphost
when using 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 applicationInitializationSection = config.GetSection("system.webServer/applicationInitialization", "Default Web Site");
applicationInitializationSection["remapManagedRequestsTo"] = @"HelloJoe.htm";
applicationInitializationSection["skipManagedModules"] = true;
applicationInitializationSection["doAppInitAfterRestart"] = true;
ConfigurationElementCollection applicationInitializationCollection = applicationInitializationSection.GetCollection();
ConfigurationElement addElement = applicationInitializationCollection.CreateElement("add");
addElement["initializationPage"] = @"JoesSite.htm";
addElement["hostName"] = @"JoesHost";
applicationInitializationCollection.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 applicationInitializationSection As ConfigurationSection = config.GetSection("system.webServer/applicationInitialization", "Default Web Site")
applicationInitializationSection("remapManagedRequestsTo") = "HelloJoe.htm"
applicationInitializationSection("skipManagedModules") = true
applicationInitializationSection("doAppInitAfterRestart") = true
Dim applicationInitializationCollection As ConfigurationElementCollection = applicationInitializationSection.GetCollection
Dim addElement As ConfigurationElement = applicationInitializationCollection.CreateElement("add")
addElement("initializationPage") = "JoesSite.htm"
addElement("hostName") = "JoesHost"
applicationInitializationCollection.Add(addElement)
serverManager.CommitChanges
End Sub
End Module
JavaScript
var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
var applicationInitializationSection = adminManager.GetAdminSection("system.webServer/applicationInitialization", "MACHINE/WEBROOT/APPHOST/Default Web Site");
applicationInitializationSection.Properties.Item("remapManagedRequestsTo").Value = "HelloJoe.htm";
applicationInitializationSection.Properties.Item("skipManagedModules").Value = true;
applicationInitializationSection.Properties.Item("doAppInitAfterRestart").Value = true;
var applicationInitializationCollection = applicationInitializationSection.Collection;
var addElement = applicationInitializationCollection.CreateNewElement("add");
addElement.Properties.Item("initializationPage").Value = "JoesSite.htm";
addElement.Properties.Item("hostName").Value = "JoesHost";
applicationInitializationCollection.AddElement(addElement);
adminManager.CommitChanges();
VBScript
Set adminManager = CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set applicationInitializationSection = adminManager.GetAdminSection("system.webServer/applicationInitialization", "MACHINE/WEBROOT/APPHOST/Default Web Site")
applicationInitializationSection.Properties.Item("remapManagedRequestsTo").Value = "HelloJoe.htm"
applicationInitializationSection.Properties.Item("skipManagedModules").Value = true
applicationInitializationSection.Properties.Item("doAppInitAfterRestart").Value = true
Set applicationInitializationCollection = applicationInitializationSection.Collection
Set addElement = applicationInitializationCollection.CreateNewElement("add")
addElement.Properties.Item("initializationPage").Value = "JoesSite.htm"
addElement.Properties.Item("hostName").Value = "JoesHost"
applicationInitializationCollection.AddElement(addElement)
adminManager.CommitChanges()
PowerShell
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -location 'Default Web Site' -filter "system.webServer/applicationInitialization" -name "remapManagedRequestsTo" -value "HelloJoe.htm"
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -location 'Default Web Site' -filter "system.webServer/applicationInitialization" -name "skipManagedModules" -value "True"
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -location 'Default Web Site' -filter "system.webServer/applicationInitialization" -name "doAppInitAfterRestart" -value "True"
Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -location 'Default Web Site' -filter "system.webServer/applicationInitialization" -name "." -value @{initializationPage='JoesSite.htm';hostName='JoesHost'}