次の方法で共有


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

概要

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

互換性

バージョン メモ
IIS 10.0 <files> 要素は、IIS 10.0 では変更されませんでした。
IIS 8.5 <files> 要素は、IIS 8.5 では変更されませんでした。
IIS 8.0 <files> 要素は、IIS 8.0 では変更されませんでした。
IIS 7.5 <files> 要素は、IIS 7.5 では変更されませんでした。
IIS 7.0 <defaultDocument> コレクションの <files> 要素は IIS 7.0 で導入されました。
IIS 6.0 <defaultDocument> コレクションは、IIS 6.0 の DefaultDoc プロパティと、IIsWebService メタベース オブジェクトの DirBrowseFlags プロパティの EnableDefaultDoc 値を置き換えます。

段取り

<defaultDocument> コレクションの <files> 要素は、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. [接続] ウィンドウで、サーバー名を展開し、[サイト] を展開して、既定のドキュメントを構成する Web サイトまたはアプリケーションに移動します。

  3. [ホーム] ウィンドウで、[既定のドキュメント] をダブルクリックします。
    Screenshot of Default Document selected in the Default Web Site Home pane.

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

  5. [既定のドキュメントの追加] ダイアログ ボックスで、追加する既定のドキュメントの名前を [名前] ボックスに入力して、[OK] をクリックします。
    Screenshot of adding a new Default Document named home dot H T M L.

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

  7. [既定のドキュメント] 警告ボックスで、[はい] をクリックして親構成レベルからの構成の継承を拒否するか、[なし] または [キャンセル] をクリックして既定のドキュメントの順序の変更を取り消します。
    Screenshot warning you before inheriting the parent level configuration for the new default document.

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

構成

属性

なし。

子要素

要素 説明
add 省略可能な要素です。

ファイルのコレクションにファイル名を追加します。
remove 省略可能な要素です。

ファイル コレクションからファイル名への参照を削除します。
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