構成パス <configPaths>

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

概要

<configPaths> 要素は、インターネット インフォメーション サービス (IIS) 7.0 分散構成ファイル システムの中で構成設定が指定されている場所をリストします。<configPaths> 要素のコンテンツは動的に生成され、プログラムを使用してアクセスして、ユーザー指定のパスからそれぞれの子孫パスに至るまでの構成設定をリストすることができます。ApplicationHost.config ファイルと Web.config ファイル内の設定も <configPaths> 要素を使用してリストすることができます。

<configPaths> 要素には、次の情報を示す <searchResult> 要素のコレクションが含まれます。

  • <searchResult> 要素の path 属性は、検索結果の構成ファイルの絶対仮想パスを示します。

  • <searchResult> 要素の locationPath 属性は、path 属性によって示される構成ファイル内の <location> タグの相対パスを示します。

    : <searchResult> 要素が config ファイルをポイントする場合、<searchResult> 要素の locationPath 属性には空の文字列が含まれます。

  • <searchResult> 要素の status 属性には、検索結果の HRESULT コードが含まれます。

  • <searchResult> 要素には、検索結果内の各要素の名前を含む <section> 要素のコレクションが含まれます。

: <configPaths> 要素およびその子要素は読み取り専用であり、エンド ユーザーが構成することはできません。

互換性

  IIS 7.0
注意 <configPaths> は IIS 7.0 で新たに導入された要素です。 なし

セットアップ

<configPaths> 要素は、IIS 7.0 の既定のインストールに含まれています。

方法

IIS 7.0 で <configPaths> 要素を構成するためのユーザー インターフェイスはありません。<configPaths> 要素をプログラムを使用して構成する方法の例については、このドキュメントの「サンプル コード」セクションを参照してください。

構成

属性

なし。

子要素

要素 説明
searchResult 構成設定の検索結果のコレクションが含まれます。

構成サンプル

: <configPaths> 要素は動的に生成されます。このため、<configPaths> 要素を構成ファイルに追加することはできません。<configPaths> 要素にプログラムを使用してアクセスする方法の例については、このドキュメントの「サンプル コード」セクションを参照してください。

サンプル コード

次のコード例では、<configPaths> 要素を使用して <system.webServer/defaultDocument> 要素ごとの Default Web Site 構成名前空間を検索し、各要素のパスと場所をコンソールに出力します。

AppCmd.exe

: AppCmd.exe を使用して <configPaths> 設定をクエリすることはできません。

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("Default Web Site");
         ConfigurationSection configPathsSection = config.GetSection("configPaths");
         ConfigurationElementCollection searchResultCollection = configPathsSection.GetCollection();

         foreach (ConfigurationElement searchResultElement in searchResultCollection)
         {
            string path = (string)searchResultElement["path"];
            string locationPath = (string)searchResultElement["locationPath"];

            foreach (ConfigurationElement sectionElement in searchResultElement.GetCollection())
            {
               if (string.Compare("system.webServer/defaultDocument",
                  (string)sectionElement["name"], false) == 0)
               {
                  Console.WriteLine("Path: " + path);
                  if (!String.IsNullOrEmpty(locationPath))
                  {
                     Console.WriteLine("\tLocation: " + locationPath);
                     Console.WriteLine("\t\tName: " + sectionElement["name"]);
                  }
                  else Console.WriteLine("\tName: " + sectionElement["name"]);
               }
            }
         } 
      }
   }
}

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.GetWebConfiguration("Default Web Site")
      Dim configPathsSection As ConfigurationSection = config.GetSection("configPaths")
      Dim searchResultCollection As ConfigurationElementCollection = configPathsSection.GetCollection
      For Each searchResultElement As ConfigurationElement In searchResultCollection
         Dim path As String = CType(searchResultElement("path"), String)
         Dim locationPath As String = CType(searchResultElement("locationPath"), String)
         For Each sectionElement As ConfigurationElement In searchResultElement.GetCollection
            If (String.Compare("system.webServer/defaultDocument", _
                  CType(sectionElement("name"), String), False) = 0) Then
               Console.WriteLine(("Path: " + path))
               If Not String.IsNullOrEmpty(locationPath) Then
                  Console.WriteLine((vbTab & "Location: " + locationPath))
                  Console.WriteLine((vbTab & vbTab & "Name: " + sectionElement("name")))
               Else
                  Console.WriteLine((vbTab & "Name: " + sectionElement("name")))
               End If
            End If
         Next
      Next
   End Sub

End Module

JavaScript

var adminManager = new ActiveXObject("Microsoft.ApplicationHost.WritableAdminManager");
var configPathsSection = adminManager.GetAdminSection("configPaths", "MACHINE/WEBROOT/APPHOST/Default Web Site");
var searchResultCollection = configPathsSection.Collection;

for (var i = 0; i < searchResultCollection.Count; i++)
{
   var searchResultElement = searchResultCollection.Item(i);
   var path = searchResultElement.GetPropertyByName("path").Value;
   var locationPath = searchResultElement.GetPropertyByName("locationPath").Value;

   sectionElementCollection = searchResultElement.Collection;
   for (var j = 0; j < sectionElementCollection.Count; j++)
   {
      var sectionElement = sectionElementCollection.Item(j);
      var name = sectionElement.GetPropertyByName("name").Value;
      if (name == "system.webServer/defaultDocument")
      {
         WScript.Echo("Path: " + path);
         if (locationPath!="")
         {
            WScript.Echo("\tLocation: " + locationPath);
            WScript.Echo("\t\tName: " + name);
         }
         else WScript.Echo("\tName: " + name);
      }
   }
}

VBScript

Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
Set configPathsSection = adminManager.GetAdminSection("configPaths", "MACHINE/WEBROOT/APPHOST/Default Web Site")
Set searchResultCollection = configPathsSection.Collection

For i = 0 To CInt(searchResultCollection.Count) - 1
   Set searchResultElement = searchResultCollection.Item(i)
   path = searchResultElement.GetPropertyByName("path").Value
   locationPath = searchResultElement.GetPropertyByName("locationPath").Value
   Set sectionElementCollection = searchResultElement.Collection
   For j = 0 To CInt(sectionElementCollection.Count) - 1
      Set sectionElement = sectionElementCollection.Item(j)
      name = sectionElement.GetPropertyByName("name").Value
      If name = "system.webServer/defaultDocument" Then
         WScript.Echo "Path: " + path
         If locationPath<>"" Then
            WScript.Echo(vbTab & "Location: " + locationPath)
            WScript.Echo(vbTab & vbTab & "Name: " + name)
         Else
            WScript.Echo(vbTab & "Name: " + name)
         End if
      End If
   Next
Next