共用方式為


組態路徑 < configPaths>

概觀

元素 <configPaths> 會列出在 Internet Information Services (IIS) 7 分散式組態檔案系統中設定組態設定的位置。 元素的內容 <configPaths> 會動態產生,並可透過程式設計方式存取,以列出從使用者指定路徑到每個子系路徑的組態設定。 您也可以使用 <configPaths> 元素,列出ApplicationHost.config和Web.config檔案中的設定。

元素 <configPaths> 包含指定下列資訊的元素集合 <searchResult>

  • 每個 <searchResult> 元素的路徑屬性會指定搜尋結果組態檔的絕對虛擬路徑。 - 每個 <searchResult> 元素的locationPath屬性會指定路徑屬性所指定組態檔內標記的相對路徑<location>

    注意

    如果元素 <searchResult> 指向.config檔案,元素的 <searchResult>locationPath屬性將會包含空字串。

  • 每個 <searchResult> 元素的狀態屬性都包含搜尋結果的 HRESULT 程式碼。

  • 每個 <searchResult> 元素都包含專案集合 <section> ,其中包含搜尋結果中每個專案的名稱。

注意

元素 <configPaths> 及其子專案是唯讀的,使用者無法設定。

相容性

版本 備註
IIS 10.0 未在 IIS 10.0 中修改專案 <configPaths>
IIS 8.5 未在 IIS 8.5 中修改專案 <configPaths>
IIS 8.0 未在 IIS 8.0 中修改專案 <configPaths>
IIS 7.5 未在 IIS 7.5 中修改專案 <configPaths>
IIS 7.0 元素 <configPaths> 是在 IIS 7.0 中引進。
IIS 6.0 N/A

安裝程式

元素 <configPaths> 包含在 IIS 7 的預設安裝中。

作法

沒有用於設定 <configPaths> IIS 7 元素的使用者介面。 For examples of how to configure the <configPaths> element programmatically, see the Code Samples section of this document.

組態

屬性

無。

子元素

元素 描述
searchResult 包含組態搜尋結果的集合。

組態範例

注意

專案 <configPaths> 會動態產生。 因此,您無法將 元素新增 <configPaths> 至組態檔。 For examples of how to access the <configPaths> element programmatically, see the Code Samples section of this document.

範例程式碼

下列程式碼範例會 <configPaths> 使用 元素來搜尋每個 <system.webServer/defaultDocument> 元素的預設網站組態命名空間,然後將每個元素的路徑和位置輸出至主控台。

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