次の方法で共有


アプリの既定値 <applicationDefaults>

概要

<site>要素の<applicationDefaults>要素は、親サイト内のすべてのアプリケーションの既定のアプリケーション設定を指定します。

<applicationDefaults> セクションと特定のアプリケーションの <application> セクションの両方で同じ属性または子要素が構成されている場合は、そのアプリケーションに対して <application> セクションの構成が使用されます。

Compatibility

バージョン 注記
IIS 10.0 <applicationDefaults>要素は IIS 10.0 では変更されませんでした。
IIS 8.5 <applicationDefaults>要素は IIS 8.5 では変更されませんでした。
IIS 8.0 preloadEnabled属性は IIS 8.0 で追加されました。
IIS 7.5 <applicationDefaults>要素は、serviceAutoStartEnabled属性とserviceAutoStartProvider属性を含むように更新されました。
IIS 7.0 <applicationDefaults> コレクションの<site>要素は、IIS 7.0 で導入されました。
IIS 6.0 <applicationDefaults>要素は、IIS 6.0 メタベースのサイト レベルでアプリケーション オプションを設定するのと似ています。

設定

<site>要素の<applicationDefaults>要素は、IIS 7 以降の既定のインストールに含まれています。

やり方

サイトの既定のアプリケーション設定を構成する方法

  1. インターネット インフォメーション サービス (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) マネージャー] をダブルクリックします。
  2. [ 接続 ] ウィンドウで、サーバー名を展開し、[ サイト ] ノードを展開し、サイトの名前をクリックします。

  3. サイトの [ホーム] ウィンドウで、[操作] ウィンドウの [アプリケーションの表示] をクリックします。
    [既定の Web サイトホーム] 画面のスクリーンショット。ドット NET コンパイル、ドット NET グローバリゼーション、およびドット NET プロファイル オプションが表示されています。

  4. サイトの [アプリケーション] ウィンドウで、[操作] ウィンドウの [アプリケーションの既定値の設定]をクリックします。
    [アプリケーション] ペインのスクリーンショット。[仮想パス] フィールドと [物理パス] フィールドが表示されています。

  5. [ アプリケーションの既定値 ] ダイアログ ボックスで、サイトの既定のアプリケーション設定を指定し、[OK] をクリック します
    [全般] セクションと [動作] セクションのスクリーンショット。

コンフィギュレーション

Attributes

特性 Description
applicationPool 省略可能な文字列属性。

親サイト内のすべてのアプリケーションが割り当てられる既定のアプリケーション プールを指定します。
enabledProtocols 省略可能な文字列属性。

親サイト内のすべてのアプリケーションとの通信に使用するプロトコルを指定します。
path 省略可能な文字列属性。

親サイト内のすべてのアプリケーションの既定の仮想パスを指定します。
preloadEnabled 省略可能な Boolean 属性です。

IIS が初期化されるように、アプリケーションまたは仮想ディレクトリの既定のページに対するユーザー要求をシミュレートするように指定します。 実際には、IIS は、要求を受け取らずにアプリケーション プールが起動されたときにアプリケーションを起動します。 これにより、マネージド モジュールの読み込みやマネージド コードのコンパイルなどの初期化タスクを実行することで、パフォーマンスが向上します。 IIS ログにログは生成されません。 アプリケーション プールの startMode 設定を AlwaysRunningに設定する必要があります。

既定値は False です。
serviceAutoStartEnabled 省略可能な Boolean 属性です。

このアプリケーションで自動開始が有効になっている場合は true。それ以外の場合は false

既定値は false です。
serviceAutoStartProvider 省略可能な文字列属性。

serviceAutoStartEnabledが true に設定されている場合に Windows プロセス アクティブ化サービス (WAS) が使用する自動開始プロバイダーの名前を指定します

既定値はありません。

子要素

なし。

構成サンプル

次の構成サンプルでは、既定の Web サイトの既定のアプリケーション プールを "DefaultAppPool" に設定します。

<sites>
   <site name="Default Web Site" id="1" serverAutoStart="true">
      <application path="/" applicationPool="Classic .NET AppPool">
         <virtualDirectory path="/" physicalPath="%SystemDrive%\inetpub\wwwroot" />
      </application>
      <bindings>
         <binding protocol="http" bindingInformation="*:80:" />
      </bindings>
      <applicationDefaults applicationPool="DefaultAppPool" />
   </site>
</sites>

サンプル コード

次のコード サンプルでは、既定の Web サイトの既定のアプリケーション プールを "DefaultAppPool" に設定します。

AppCmd.exe

appcmd.exe set config -section:system.applicationHost/sites "/[name='Default Web Site'].applicationDefaults.applicationPool:DefaultAppPool" /commit:apphost

AppCmd.exe を使用してこれらの設定を構成する場合は、 コミット パラメーターを必ず 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", @"Default Web Site");
         if (siteElement == null) throw new InvalidOperationException("Element not found!");

         ConfigurationElement applicationDefaultsElement = siteElement.GetChildElement("applicationDefaults");
         applicationDefaultsElement["applicationPool"] = @"DefaultAppPool";

         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", "Default Web Site")
      If (siteElement Is Nothing) Then
         Throw New InvalidOperationException("Element not found!")
      End If

      Dim applicationDefaultsElement As ConfigurationElement = siteElement.GetChildElement("applicationDefaults")
      applicationDefaultsElement("applicationPool") = "DefaultAppPool"

      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", "Default Web Site"]);
if (siteElementPos == -1) throw "Element not found!";
var siteElement = sitesCollection.Item(siteElementPos);

var applicationDefaultsElement = siteElement.ChildElements.Item("applicationDefaults");
applicationDefaultsElement.Properties.Item("applicationPool").Value = "DefaultAppPool";

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;
}

VB スクリプト

Set adminManager = WScript.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", "Default Web Site"))
If (siteElementPos = -1) Then
   WScript.Echo "Element not found!"
   WScript.Quit
End If
Set siteElement = sitesCollection.Item(siteElementPos)

Set applicationDefaultsElement = siteElement.ChildElements.Item("applicationDefaults")
applicationDefaultsElement.Properties.Item("applicationPool").Value = "DefaultAppPool"

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