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>