.net获取iis全部站点和对应端口

   /// <summary>
        /// 扫码通过后跳转到目录浏览界面
        /// </summary>
        protected void JumpDirectory()
        {
    
    
            //获取iis全部的网站名称和对应的url地址
            List<IIsWeb> webs = new List<IIsWeb>();

            DirectoryEntry rootEntry = new DirectoryEntry("IIS://localhost/w3svc");

            foreach (DirectoryEntry entry in rootEntry.Children)
            {
    
    
                if (entry.SchemaClassName.Equals("IIsWebServer", StringComparison.OrdinalIgnoreCase))
                {
    
    
                    IIsWeb web = new IIsWeb();
                    web.name = entry.Properties["ServerComment"].Value.ToString();//网站名称
                    web.port = $"{ConfigurationManager.AppSettings["Proj"]}{entry.Properties["ServerBindings"].Value}";//网站端口
                    webs.Add(web);
                }
            }
        }

效果
在这里插入图片描述

Guess you like

Origin blog.csdn.net/q1923408717/article/details/118091611