概述
<configPaths> 元素列出在 Internet Information Services (IIS) 7 分布式配置文件系统中设置配置设置的位置。 <configPaths> 元素的内容是动态生成的,可通过编程方式访问以列出从用户指定的路径到每个后代路径的配置设置。 还可以使用 <configPaths> 元素列出 ApplicationHost.config 和 Web.config 文件中的设置。
<configPaths> 元素包含指定以下信息的 <searchResult> 元素集合:
每个 元素的 path 属性指定搜索结果配置文件的绝对虚拟路径
<searchResult>。 - 每个<searchResult>元素的 locationPath 属性指定配置文件中由 path 属性指定的<location>标记的相对路径。注意
如果
<searchResult>元素指向 .config 文件,则<searchResult>元素的 locationPath 属性将包含一个空字符串。每个
<searchResult>元素的 status 属性都包含搜索结果的 HRESULT 代码。每个
<searchResult>元素都包含<section>元素集合,其中包含搜索结果中每个元素的名称。
注意
<configPaths> 元素及其子元素是只读的,不能由最终用户配置。
兼容性
| 版本 | 说明 |
|---|---|
| IIS 10.0 | <configPaths> 元素在 IIS 10.0 中未进行修改。 |
| IIS 8.5 | <configPaths> 元素在 IIS 8.5 中未进行修改。 |
| IIS 8.0 | <configPaths> 元素在 IIS 8.0 中未进行修改。 |
| IIS 7.5 | <configPaths> 元素未在 IIS 7.5 中进行修改。 |
| IIS 7.0 | <configPaths> 元素是在 IIS 7.0 中引入的。 |
| IIS 6.0 | 空值 |
安装
<configPaths> 元素包含在 IIS 7 的默认安装中。
操作方式
IIS 7 中没有用于配置 <configPaths> 元素的用户界面。 若要通过示例来了解如何以编程方式配置 <configPaths> 元素,请参阅本文档的代码示例部分。
配置
特性
无。
子元素
| 元素 | 说明 |
|---|---|
searchResult |
包含配置搜索结果的集合。 |
配置示例
注意
会自动生成 <configPaths> 元素。 因此,无法向配置文件添加 <configPaths> 元素。 有关如何以编程方式访问 <configPaths> 元素的示例,请参阅本文档的代码示例部分。
代码示例
下面的代码示例使用 <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