既定のドキュメント ファイル <files>

  • 概要
  • 互換性
  • セットアップ
  • 方法
  • 構成
  • サンプル コード

※本ページに挿入されている画像をクリックすると、画像全体が別ウィンドウで表示されます。

概要

<defaultDocument> コレクションの <files> 要素は、既定のドキュメントとして構成されるファイル名の一覧を指定します。<files> 要素は、<add> 要素の一覧を含むことができます。その場合、一覧内の各アイテムにより、<files> 一覧に追加する固有のファイルが指定されます。

互換性

  IIS 7.0 IIS 6.0
注意 <defaultDocument> コレクションの <files> は IIS 7.0 で新たに導入された要素です。

<defaultDocument> コレクションは、IIS 6.0 の IIsWebService メタベース オブジェクトの DefaultDoc プロパティ、および DirBrowseFlags プロパティの EnableDefaultDoc 値に代わるものです。

セットアップ

<defaultDocument> コレクションの <files> 要素は、IIS 7.0 の既定のインストールに含まれています。

方法

アプリケーションまたはサイトの既定のドキュメントを追加する方法

  1. タスク バーで [スタート] ボタンをクリックし、[管理ツール] をポイントして [インターネット インフォメーション サービス (IIS) マネージャー] をクリックします。

  2. [接続] ウィンドウで当該サーバー名を展開して [サイト] を展開し、既定のドキュメントを構成する Web サイトまたはアプリケーションを選択します。

  3. [ホーム] ウィンドウで [既定のドキュメント] をダブルクリックします。

    拡大

  4. [操作] ウィンドウで [追加] をクリックします。

  5. [既定のドキュメントを追加] ダイアログ ボックスで、追加する既定のドキュメントの名前を [名前] ボックスに入力し、[OK] をクリックします。

    拡大

  6. 必要に応じて、[操作] ウィンドウで一覧内の既定のドキュメントを選択し、[上へ移動] または [下へ移動] をクリックして、IIS で既定のドキュメントの一覧が検索される順序を定義します。

  7. [既定のドキュメント] 警告ボックスで、親構成レベルからの構成の継承を拒否する場合は [はい] を、既定のドキュメントの順序に加えた変更をキャンセルする場合は [いいえ] または [キャンセル] をクリックします。

    拡大

  8. 必要に応じて、[操作] ウィンドウで [削除] をクリックして、既定のドキュメントとして使用しないファイル名を削除します。

構成

属性

なし。

子要素

要素 説明
add オプションの要素。

ファイルのコレクションにファイル名を追加します。
remove オプションの要素。

ファイル コレクションから 1 つのファイル名への参照を削除します。
clear オプションの要素。

ファイル コレクションからファイル名へのすべての参照を削除します。

構成サンプル

次の構成例がサイトまたはアプリケーションの Web.config ファイルに組み込まれると、そのサイトまたはアプリケーションの既定のドキュメントが有効になります。また、サイトまたはアプリケーションの既定のドキュメントの一覧に "Home.html" というファイル名が追加されます。

<configuration>
   <system.webServer>
      <defaultDocument enabled="true">
         <files>

            <add value="home.html" />
         </files>
      </defaultDocument>
   </system.webServer>
</configuration>

サンプル コード

次の例では、Contoso という名前の Web サイト上の既定のドキュメントが有効になります。また、同サイトの既定のドキュメントの一覧に Home.html という名前のファイルが追加されます。

AppCmd.exe

appcmd.exe set config "Contoso" /section:defaultDocument /enabled:true /+files.[value='home.html'] 

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.GetWebConfiguration("Contoso");
            
            ConfigurationSection defaultDocumentSection = config.GetSection("system.webServer/defaultDocument");
            
            defaultDocumentSection["enabled"] = true;
            
            ConfigurationElementCollection filesCollection = defaultDocumentSection.GetCollection("files");
            ConfigurationElement addElement = filesCollection.CreateElement("add");
            addElement["value"] = @"home.html";
            filesCollection.AddAt(0, addElement);
            
            serverManager.CommitChanges();
        }
    }
}

VB.NET

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

Class Sample
   Shared Sub Main()
      Dim serverManager As ServerManager = New ServerManager
      Dim config As Configuration = serverManager.GetWebConfiguration("Contoso")
      Dim defaultDocumentSection As ConfigurationSection = config.GetSection("system.webServer/defaultDocument")

      defaultDocumentSection("enabled") = True

      Dim filesCollection As ConfigurationElementCollection = defaultDocumentSection.GetCollection("files")
      Dim addElement As ConfigurationElement = filesCollection.CreateElement("add")
      addElement("value") = "home.html"
      filesCollection.AddAt(0, addElement)

      serverManager.CommitChanges()
   End Sub
End Class

JavaScript

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

var defaultDocumentSection = adminManager.GetAdminSection("system.webServer/defaultDocument",
   "MACHINE/WEBROOT/APPHOST/Contoso");

defaultDocumentSection.Properties.Item("enabled").Value = true;

var filesCollection = defaultDocumentSection.ChildElements.Item("files").Collection;

var addElement = filesCollection.CreateNewElement("add");
addElement.Properties.Item("value").Value = "home.html";
filesCollection.AddElement(addElement, 0);

adminManager.CommitChanges();

VBScript

Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Contoso"

Set defaultDocumentSection = adminManager.GetAdminSection("system.webServer/defaultDocument", _
   "MACHINE/WEBROOT/APPHOST/Contoso")

defaultDocumentSection.Properties.Item("enabled").Value = True  

Set filesCollection = defaultDocumentSection.ChildElements.Item("files").Collection

Set addElement = filesCollection.CreateNewElement("add")
addElement.Properties.Item("value").Value = "home.html"
filesCollection.AddElement addElement, 0

adminManager.CommitChanges