Application Initialization <applicationInitialization>
Overview
The <applicationInitialization>
element specifies that web application initialization is performed proactively before a request is received. An application can start up more quickly if initialization sequences such as initializing connections, priming in-memory caches, running queries, and compiling page code are performed before the HTTP request is received. Application Initialization can start the initialization process automatically whenever an application is started. The application initialization does not necessarily make the initialization process run any faster; it starts the process sooner.
Application initialization also enables you to enhance the user experience during initialization by redirecting a request to static pages, such as a placeholder or splash screen. Once the site is loaded, it will stop mapping the managed request to the static page, and will start serving the dynamic content. When using the remapManagedRequestsTo attribute in the <applicationInitialization>
element, you can only map the managed request to a single page. However, application initialization can be used in conjunction with the out-of-band IIS Url Rewrite module to support more complex handling of placeholder content, including complex mappings to pre-generated static content.
In addition to application initialization, you can enable the initialization process to start whenever the application pool is started. You do so by setting the preLoadEnabled attribute in the <application>
element to "true". For this to occur, the start mode in the <applicationPool>
element must be set to AlwaysRunning.
Compatibility
Version | Notes |
---|---|
IIS 10.0 | The <applicationInitialization> element was not modified in IIS 10.0. |
IIS 8.5 | The <applicationInitialization> element was not modified in IIS 8.5. |
IIS 8.0 | The <applicationInitialization> 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 <applicationInitialization>
element is configured at the server, site, or application level.
Attributes
Attribute | Description |
---|---|
doAppInitAfterRestart |
Optional Boolean attribute. Specifies that the initialization process is initiated automatically whenever an application restart occurs. Note that this is different than the preLoadEnabled attribute in the application element, which specifies that the initialization process is started after a restart of the application pool. The default value is false . |
remapManagedRequestsTo |
Optional string attribute. Specifies a page to remap a request to during application initialization. The default value is "" . |
skipManagedModules |
Optional Boolean attribute. Specifies whether the managed modules are loaded ( false ) or not loaded (true ) during initialization.The default value is false . |
Child Elements
Element | Description |
---|---|
add |
Optional element. Specifies the application to be initialized upon application restart. |
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'}