1

IIS の applicationHost.xml.config ファイルを読んでいます。サイト内の各サイトの仮想ディレクトリを取得し、その時点から必要な情報を取得しています。物理パスやパスなどの情報。次に、バインディングを取得する必要があります。

2 つのアプリケーション ノードがある場合、"Bindings" 要素ノードに効果的に到達する方法がわかりません。(この例を以下に示します)ただし、「site.ParentNode.NextSibling.ChildNodes」を使用して、アプリケーション ノードが 1 つの場合にそれぞれのバインディングのリストを取得できます。

よろしくお願いします。

私のコード:

XDocument.Load(@"C:\\windows\\system32\\inetsrv\\config\\applicationHost.config");
XmlNodeList siteList = XDocument.SelectNodes("/configuration/system.applicationHost/sites/site/application/virtualDirectory");

foreach (XmlNode site in siteList)
{
    XmlAttribute XmlAttributeParentParentName = (XmlAttribute)site.ParentNode.ParentNode.Attributes.GetNamedItem("name");
    XmlAttribute XmlAttributePath = (XmlAttribute)site.Attributes.GetNamedItem("path");
    XmlAttribute XmlAttributePhysicalPath = (XmlAttribute)site.Attributes.GetNamedItem("physicalPath");
    XmlNodeList BindingList = (XmlNodeList)site.ParentNode.NextSibling.ChildNodes;

    string path = XmlAttributePath.Value.ToString();
    string siteName = XmlAttributeParentParentName.Value.ToString();
    string physicalPath = XmlAttributePhysicalPath.Value.ToString();
    string firstBindingElement = BindingList[0].Attributes.GetNamedItem("bindingInformation").Value.ToString();

    //do something with the variables.
    //rest of code is here
}

次に、サイト ノードの例を示します。

<site name="Site Name" id="20" serverAutoStart="true">
  <application path="/" applicationPool="SiteAppPool">
      <virtualDirectory path="/" physicalPath="C:\inetpub\wwwroot\SiteName" />
  </application>
  <application path="/store" applicationPool="SiteAppPool">
      <virtualDirectory path="/" physicalPath="C:\inetpub\wwwroot\SiteName\store" />
  </application>
  <bindings>
      <binding protocol="http" bindingInformation="*:80:sitename.com" />
  </bindings>
</site>
4

1 に答える 1

0

ここで何かが欠けていないことを願っていますが、次のように反復 XmlNode で SelectNodes を使用できませんでした:

XmlNodeList BindingList = (XmlNodeList)site.SelectNodes("../../bindings/binding");

これにより、反復ノードのルート (virtualDirectory ノード) からその親 (アプリケーション ノード)、その親 (サイト ノード)、バインディング ノード、最後にバインディングのリストに移動します。この中のノード?

于 2013-05-13T20:49:58.990 に答える