.NET 获取IIS中网站名称和属性

  // 遍厉IIS
        DirectoryEntry directoryEntry  =   new  DirectoryEntry( @" IIS://localhost/W3SVC " );
        IEnumerator ienum 
=  directoryEntry.Children.GetEnumerator();
        
string  HostInfo = "" ;
        
while  (ienum.MoveNext())
        
{
            DirectoryEntry entrypool 
= (DirectoryEntry)ienum.Current;
            System.DirectoryServices.PropertyCollection ppC 
= (System.DirectoryServices.PropertyCollection)entrypool.Properties;
            IDictionaryEnumerator idenum 
= ppC.GetEnumerator();
            
if (entrypool.SchemaClassName == "IIsWebServer")
            
{
                
string[] serverBind = ppC["ServerBindings"][0].ToString().Split(':');//获取网站绑定的IP,端口,主机头
                string EnableDeDoc = ppC["EnableDefaultDoc"][0].ToString();
                
string DefaultDoc = ppC["DefaultDoc"][0].ToString();//默认文档
                string MaxConnections = ppC["MaxConnections"][0].ToString();//iis连接数,-1为不限制
                string ConnectionTimeout = ppC["ConnectionTimeout"][0].ToString();//连接超时时间
                string MaxBandwidth = ppC["MaxBandwidth"][0].ToString();//最大绑定数
                string ServerState = ppC["ServerState"][0].ToString();//运行状态
                
                HostInfo 
+= "站台名称:" + ppC["ServerComment"][0].ToString() + "-- 网站IP:" + serverBind[0].ToString() + "--网站端口:" + serverBind[1].ToString() + "--主机头" + serverBind[2].ToString() + "<br>";//获取IIS下所有站点名称
                HostInfo += EnableDeDoc + "<br>";
                HostInfo 
+= DefaultDoc + "<br>";
                HostInfo 
+= MaxConnections + "<br>";
                HostInfo 
+= ConnectionTimeout + "<br>";
                HostInfo 
+= MaxBandwidth + "<br>";
                HostInfo 
+= ServerState + "<br>";
                
            }

        }

        Response.Write(HostInfo);
        Response.End();
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值