概要
<application>
要素では、特定のアプリケーションの構成設定を制御します。 インターネット インフォメーション サービス (IIS) 7 以降でのアプリケーションは、HTTP などのプロトコル経由でコンテンツを配信したり、サービスを提供したりする一連のファイルです。 IIS 7 以降でアプリケーションを作成すると、アプリケーションのパスがサイトの URL の一部になります。
IIS 7 以降では、各サイトにはルート アプリケーションまたは既定のアプリケーションと呼ばれるアプリケーションが少なくとも 1 つ必要です。 ただし、1 つのサイトに複数のアプリケーションを含めることができます。 たとえば、オンライン コマース Web サイトでは、ユーザーがショッピング中にアイテムを収集できるショッピング カート アプリケーションや、ユーザーが購入時に保存された支払い情報を思い出すためのログイン アプリケーションなどの複数のアプリケーションを含むことができます。
アプリケーションには、ルートまたは既定の仮想ディレクトリと呼ばれる仮想ディレクトリが少なくとも 1 つ含まれている必要があり、構成設定は <virtualDirectory>
要素で定義されています。
互換性
バージョン | メモ |
---|---|
IIS 10.0 | <application> 要素は、IIS 10.0 では変更されませんでした。 |
IIS 8.5 | <application> 要素は、IIS 8.5 では変更されませんでした。 |
IIS 8.0 | preloadEnabled 属性が、要求を受信する前に初期化プロセスを開始するために追加されました。 |
IIS 7.5 | <application> 要素は、serviceAutoStartEnabled 属性と serviceAutoStartProvider 属性を含むように更新されました。 |
IIS 7.0 | <application> 要素が IIS 7.0 で導入されました。 |
IIS 6.0 | <application> 要素は、IIS 6.0 IIsWebVirtualDir と IIsWebDirectory のメタベース オブジェクトを置き換えます。 |
段取り
<application>
要素は IIS 7 以降の既定のインストールに含まれています。
操作方法
新しい Web アプリケーションを作成する方法
インターネット インフォメーション サービス (IIS) マネージャーを開きます。
Windows Server 2012 または Windows Server 2012 R2 を使用している場合:
- タスク バーで、[サーバー マネージャー] をクリックし、[ツール]、[インターネット インフォメーション サービス (IIS) マネージャー] の順にクリックします。
Windows 8 または Windows 8.1 を使用している場合:
- Windows キーを押しながら文字 X を押し、[コントロール パネル] をクリックします。
- [管理ツール] をクリックし、[インターネット インフォメーション サービス (IIS) マネージャー] をダブルクリックします。
Windows Server 2008 または Windows Server 2008 R2 を使用している場合:
- タスク バーで、[スタート] ボタンをクリックし、[管理ツール]、[インターネット インフォメーション サービス (IIS) マネージャー] の順にクリックします。
Windows Vista または Windows 7 を使用している場合:
- タスク バーで、[スタート]、[コントロール パネル] の順にクリックします。
- [管理ツール] をダブルクリックし、[インターネット インフォメーション サービス (IIS) マネージャー] をダブルクリックします。
[接続] ウィンドウでサーバー名を展開し、[サイト] を展開してから、アプリケーションを追加する Web サイトをクリックします。
[操作] ウィンドウで、[アプリケーションの表示] をクリックし、[アプリケーションの追加...] をクリックします。
[アプリケーションの追加] ダイアログ ボックスで、少なくとも [エイリアス:] と [物理パス:] テキスト ボックスに情報を入力し、[OK] をクリックします。
Note
[選択] をクリックして、別のアプリケーション プールを選択したり、[接続] をクリックして、特定のアカウントからの資格情報を受け入れるようにアプリケーションを構成したり、[設定のテスト] をクリックして、アプリケーションの認証と承認の設定をテストしたりすることができます。
構成
<application>
要素は、ApplicationHost.config ファイルにサーバー レベルで構成できます。
属性
属性 | 説明 |
---|---|
applicationPool |
省略可能な文字列属性。 アプリケーションが割り当てられるアプリケーション プールを指定します。 既定値はありません。 |
enabledProtocols |
省略可能な文字列属性。 アプリケーションとの通信に使用するプロトコルを指定します。 この値により、アプリケーションの HTTP プロトコルと HTTPS プロトコルが有効になります。 既定値は http です。 |
path |
必須の文字列属性です。 アプリケーションの仮想パスを指定します。 親サイト内の一意のパスである必要があります。 既定値はありません。 |
preloadEnabled |
省略可能な Boolean 属性です。 アプリケーションまたは仮想ディレクトリの既定のページが初期化されるように、そのページに対するユーザー要求を IIS がシミュレートすることを指定します。 実質的に、要求を受け取っていなくてもアプリケーション プールが起動されたときに IIS がアプリケーションを起動します。 これで、マネージド モジュールの読み込みやマネージド コードのコンパイルなどの初期化タスクが実行されるため、パフォーマンスが向上します。 IIS ログにログは生成されません。 アプリケーション プールの startMode 設定を AlwaysRunning に設定する必要があります。既定値は False です。 |
serviceAutoStartEnabled |
省略可能な Boolean 属性です。 このアプリケーションの自動開始を有効にする場合は true、それ以外の場合は false。 既定値は false です。 |
serviceAutoStartProvider |
省略可能な文字列属性。serviceAutoStartEnabled を true に設定する場合は、Windows プロセス アクティブ化サービス (WAS) が使用する自動開始プロバイダーの名前を指定します。既定値はありません。 |
子要素
要素 | 説明 |
---|---|
virtualDirectory |
省略可能な要素です。 親アプリケーション内の仮想ディレクトリの構成設定を指定します。 |
virtualDirectoryDefaults |
省略可能な要素です。 親アプリケーション内のすべての仮想ディレクトリの既定の設定を指定します。 |
構成サンプル
次の構成例では、2 つのアプリケーションを含む <site>
要素を表示します。 最初の <application>
要素では、サイトのルート アプリケーションと、アプリケーションのルート仮想ディレクトリを定義します。 2 番目の <application>
要素には、Web サイト上の CRM アプリケーションの構成設定が含まれています。 path 属性では、アプリケーションのパスを定義します。 この <application>
要素には、2 つの <virtualDirectory>
要素が含まれています。 1 つ目ではアプリケーションのルート仮想ディレクトリを定義し、2 つ目ではアプリケーションの Images 仮想ディレクトリを定義します。
<site name="Contoso" id="2" serverAutoStart="true">
<application path="/">
<virtualDirectory path="/" physicalPath="C:\Contoso\Content" />
</application>
<application path="/CRM">
<virtualDirectory path="/" physicalPath="C:\Contoso\Content\CRM" />
<virtualDirectory path="/Images" physicalPath="E:\Images" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:80:www.contoso.com" />
</bindings>
</site>
サンプル コード
次の例では、Contoso という名前のサイトの C:\Inetpub\Contoso\ShoppingCart の仮想ディレクトリ ルートを持つ ShoppingCart という名前の新しいアプリケーションを作成します。
Note
コマンド プロンプトまたはスクリプトからアプリケーションを作成する場合は、そのアプリケーションのルート仮想ディレクトリを明示的に作成する必要があります。
AppCmd.exe
appcmd.exe set config -section:system.applicationHost/sites /+"[name='Contoso'].[path='/ShoppingCart']" /commit:apphost
appcmd.exe set config -section:system.applicationHost/sites /+"[name='Contoso'].[path='/ShoppingCart'].[path='/',physicalPath='C:\Inetpub\Contoso\ShoppingCart']" /commit:apphost
Note
AppCmd.exe を使用してこれらの設定を構成するときは、commit パラメーターを必ず apphost
に設定する必要があります。 これで、ApplicationHost.config ファイルの適切な場所セクションに構成設定がコミットされます。
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 sitesSection = config.GetSection("system.applicationHost/sites");
ConfigurationElementCollection sitesCollection = sitesSection.GetCollection();
ConfigurationElement siteElement = FindElement(sitesCollection, "site", "name", @"Contoso");
if (siteElement == null) throw new InvalidOperationException("Element not found!");
ConfigurationElementCollection siteCollection = siteElement.GetCollection();
ConfigurationElement applicationElement = siteCollection.CreateElement("application");
applicationElement["path"] = @"/ShoppingCart";
ConfigurationElementCollection applicationCollection = applicationElement.GetCollection();
ConfigurationElement virtualDirectoryElement = applicationCollection.CreateElement("virtualDirectory");
virtualDirectoryElement["path"] = @"/";
virtualDirectoryElement["physicalPath"] = @"C:\Inetpub\Contoso\ShoppingCart";
applicationCollection.Add(virtualDirectoryElement);
siteCollection.Add(applicationElement);
serverManager.CommitChanges();
}
}
private static ConfigurationElement FindElement(ConfigurationElementCollection collection, string elementTagName, params string[] keyValues)
{
foreach (ConfigurationElement element in collection)
{
if (String.Equals(element.ElementTagName, elementTagName, StringComparison.OrdinalIgnoreCase))
{
bool matches = true;
for (int i = 0; i < keyValues.Length; i += 2)
{
object o = element.GetAttributeValue(keyValues[i]);
string value = null;
if (o != null)
{
value = o.ToString();
}
if (!String.Equals(value, keyValues[i + 1], StringComparison.OrdinalIgnoreCase))
{
matches = false;
break;
}
}
if (matches)
{
return element;
}
}
}
return null;
}
}
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 sitesSection As ConfigurationSection = config.GetSection("system.applicationHost/sites")
Dim sitesCollection As ConfigurationElementCollection = sitesSection.GetCollection
Dim siteElement As ConfigurationElement = FindElement(sitesCollection, "site", "name", "Contoso")
If (siteElement Is Nothing) Then
Throw New InvalidOperationException("Element not found!")
End If
Dim siteCollection As ConfigurationElementCollection = siteElement.GetCollection
Dim applicationElement As ConfigurationElement = siteCollection.CreateElement("application")
applicationElement("path") = "/ShoppingCart"
Dim applicationCollection As ConfigurationElementCollection = applicationElement.GetCollection
Dim virtualDirectoryElement As ConfigurationElement = applicationCollection.CreateElement("virtualDirectory")
virtualDirectoryElement("path") = "/"
virtualDirectoryElement("physicalPath") = "C:\Inetpub\Contoso\ShoppingCart"
applicationCollection.Add(virtualDirectoryElement)
siteCollection.Add(applicationElement)
serverManager.CommitChanges()
End Sub
Private Function FindElement(ByVal collection As ConfigurationElementCollection, ByVal elementTagName As String, ByVal ParamArray keyValues() As String) As ConfigurationElement
For Each element As ConfigurationElement In collection
If String.Equals(element.ElementTagName, elementTagName, StringComparison.OrdinalIgnoreCase) Then
Dim matches As Boolean = True
Dim i As Integer
For i = 0 To keyValues.Length - 1 Step 2
Dim o As Object = element.GetAttributeValue(keyValues(i))
Dim value As String = Nothing
If (Not (o) Is Nothing) Then
value = o.ToString
End If
If Not String.Equals(value, keyValues((i + 1)), StringComparison.OrdinalIgnoreCase) Then
matches = False
Exit For
End If
Next
If matches Then
Return element
End If
End If
Next
Return Nothing
End Function
End Module
JavaScript
var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
var sitesSection = adminManager.GetAdminSection("system.applicationHost/sites", "MACHINE/WEBROOT/APPHOST");
var sitesCollection = sitesSection.Collection;
var siteElementPos = FindElement(sitesCollection, "site", ["name", "Contoso"]);
if (siteElementPos == -1) throw "Element not found!";
var siteElement = sitesCollection.Item(siteElementPos);
var siteCollection = siteElement.Collection;
var applicationElement = siteCollection.CreateNewElement("application");
applicationElement.Properties.Item("path").Value = "/ShoppingCart";
var applicationCollection = applicationElement.Collection;
var virtualDirectoryElement = applicationCollection.CreateNewElement("virtualDirectory");
virtualDirectoryElement.Properties.Item("path").Value = "/";
virtualDirectoryElement.Properties.Item("physicalPath").Value = "C:\\Inetpub\\Contoso\\ShoppingCart";
applicationCollection.AddElement(virtualDirectoryElement);
siteCollection.AddElement(applicationElement);
adminManager.CommitChanges();
function FindElement(collection, elementTagName, valuesToMatch) {
for (var i = 0; i < collection.Count; i++) {
var element = collection.Item(i);
if (element.Name == elementTagName) {
var matches = true;
for (var iVal = 0; iVal < valuesToMatch.length; iVal += 2) {
var property = element.GetPropertyByName(valuesToMatch[iVal]);
var value = property.Value;
if (value != null) {
value = value.toString();
}
if (value != valuesToMatch[iVal + 1]) {
matches = false;
break;
}
}
if (matches) {
return i;
}
}
}
return -1;
}
VBScript
Set adminManager = CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set sitesSection = adminManager.GetAdminSection("system.applicationHost/sites", "MACHINE/WEBROOT/APPHOST")
Set sitesCollection = sitesSection.Collection
siteElementPos = FindElement(sitesCollection, "site", Array("name", "Contoso"))
If (siteElementPos = -1) Then
WScript.Echo "Element not found!"
WScript.Quit
End If
Set siteElement = sitesCollection.Item(siteElementPos)
Set siteCollection = siteElement.Collection
Set applicationElement = siteCollection.CreateNewElement("application")
applicationElement.Properties.Item("path").Value = "/ShoppingCart"
Set applicationCollection = applicationElement.Collection
Set virtualDirectoryElement = applicationCollection.CreateNewElement("virtualDirectory")
virtualDirectoryElement.Properties.Item("path").Value = "/"
virtualDirectoryElement.Properties.Item("physicalPath").Value = "C:\Inetpub\Contoso\ShoppingCart"
applicationCollection.AddElement(virtualDirectoryElement)
siteCollection.AddElement(applicationElement)
adminManager.CommitChanges()
Function FindElement(collection, elementTagName, valuesToMatch)
For i = 0 To CInt(collection.Count) - 1
Set element = collection.Item(i)
If element.Name = elementTagName Then
matches = True
For iVal = 0 To UBound(valuesToMatch) Step 2
Set property = element.GetPropertyByName(valuesToMatch(iVal))
value = property.Value
If Not IsNull(value) Then
value = CStr(value)
End If
If Not value = CStr(valuesToMatch(iVal + 1)) Then
matches = False
Exit For
End If
Next
If matches Then
Exit For
End If
End If
Next
If matches Then
FindElement = i
Else
FindElement = -1
End If
End Function