简体   繁体   English

WMI - IIS 7 - 检索所有网站绑定

[英]WMI - IIS 7 - Retrieve all website bindings

Im trying to find some sample code that shows how use the WMI ( using C#) to query a remote IIS 7 for all website bindings. 我试图找到一些示例代码,显示如何使用WMI(使用C#)查询远程IIS 7的所有网站绑定。 I cant make heads or tails of all the classes/ name spaces and querys that need to be made to accomplish this. 我无法使所有类/名称空间和查询的头部或尾部需要完成此操作。 If no sample code is available i would love some refrences to good documentation. 如果没有可用的示例代码,我会喜欢对良好文档的一些参考。

Thanks alot 非常感谢

You should be able to accomplish this by accessing the IIS metabase, using the System.DirectoryServices assembly. 您应该能够通过使用System.DirectoryServices程序集访问IIS元数据库来完成此操作。

For example, here you can enumerate through all of your sites and property configurations contained within those sites. 例如,您可以在此处枚举这些站点中包含的所有站点和属性配置。

Add this reference to your project: 将此引用添加到项目中:

using System.DirectoryServices

// Assuming your Server Id is 1, and you are connecting to your local IIS.
DirectoryEntry de = new DirectoryEntry(@"IIS://localhost/W3SVC/1/Root");
foreach (DirectoryEntry entry in de.Children)
{
   foreach (PropertyValueCollection property in entry.Properties)
   {
      Console.WriteLine("Name: {0}, Value {1}",property.PropertyName, property.Value);
   }
}

You need to use the ServerManager.OpenRemote("serverName") function to connect to an external IIS instance. 您需要使用ServerManager.OpenRemote("serverName")函数连接到外部IIS实例。 (See the msdn article here .) (请参阅此处的msdn文章。)

If you enumerate through serverManager.Sites collection you can then retrieve the site.Bindings property from each Site object to see the bindings that are active on that website. 如果通过serverManager.Sites集合枚举,则可以从每个Site对象检索site.Bindings属性,以查看在该网站上处于活动状态的绑定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM