using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.DirectoryServices;
using System.Diagnostics; namespace WindowsFormsApplication13
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} void ShowEntry(DirectoryEntry entry)
{
foreach (DirectoryEntry childEntry in entry.Children)
{
if (childEntry.SchemaClassName == "IIsWebServer")
{
Debug.Print(childEntry.SchemaClassName + ":" + childEntry.Properties["ServerComment"].Value.ToString());
Debug.Print("*********************Start*************************");
foreach (var name in childEntry.Properties.PropertyNames)
{
Debug.Print(name + ":" + childEntry.Properties[name.ToString()].Value);
}
Debug.Print("*********************End*************************");
}
else if (childEntry.SchemaClassName == "IIsWebVirtualDir")
{
Debug.Print(childEntry.SchemaClassName + ":" + childEntry.Name);
Debug.Print("*********************Start*************************");
foreach (var name in childEntry.Properties.PropertyNames)
{
Debug.Print(name + ":" + childEntry.Properties[name.ToString()].Value);
}
Debug.Print("*********************End*************************");
}
else
{
//Debug.Print(childEntry.SchemaClassName);
}
ShowEntry(childEntry);
}
} private void Form1_Load(object sender, EventArgs e)
{
ShowEntry(new DirectoryEntry("IIS://localhost/w3svc"));
}
}
}

获取IIS树型目录:

public class SiteInfo
{
public string Name { get; set; }
public string Path { get; set; }
public bool IsApp { get; set; }
public List<SiteInfo> Children { get; set; }
} List<SiteInfo> getSiteList(DirectoryEntry entry)
{
var result = new List<SiteInfo>();
foreach (DirectoryEntry childEntry in entry.Children)
{
var sites = getSiteList(childEntry);
if (childEntry.SchemaClassName == "IIsWebServer")
{
var site = new SiteInfo();
site.Name = childEntry.Properties["ServerComment"].Value.ToString();
site.Path = sites[].Path;
site.IsApp = true;
site.Children = new List<SiteInfo>();
foreach (var subSite in sites[].Children)
site.Children.Add(subSite);
result.Add(site);
}
else if (childEntry.SchemaClassName == "IIsWebVirtualDir")
{
var site = new SiteInfo();
site.Name = childEntry.Name;
site.Path = childEntry.Properties["Path"].Value.ToString();
site.Children = sites;
if (childEntry.Properties.Contains("AppRoot")
&& childEntry.Properties["AppRoot"].Value != null
&& !string.IsNullOrEmpty(childEntry.Properties["AppRoot"].Value.ToString()))
site.IsApp = true;
result.Add(site);
}
}
return result;
}
        public List<KeyValuePair<SiteInfo, string>> getFlatSiteList(List<SiteInfo> sites, string parentPadding = "")
{
var result = new List<KeyValuePair<SiteInfo, string>>();
foreach (var site in sites)
{
var currentPrefix = parentPadding == string.Empty ? string.Empty : "└" + parentPadding;
result.Add(new KeyValuePair<SiteInfo, string>(site, currentPrefix + site.Name));
result.AddRange(getFlatSiteList(site.Children, parentPadding + "--"));
}
return result;
} private void Form1_Load(object sender, EventArgs e)
{
var siteList = getSiteList(new DirectoryEntry("IIS://localhost/w3svc"));
var flatSiteList = getFlatSiteList(siteList);
foreach (var list in flatSiteList)
Debug.Print(list.Value);
}

C#获取IIS所有站点及虚拟目录和应用程序(包含名称及详细信息)的更多相关文章

  1. IIS - 虚拟目录与应用程序的异同

    在Windows 7 IIS7中,对服务器建立站点后,有二种添加子站点的方式 A. 虚拟目录 B. 应用程序   简单总结下二者之间的异同 A.虚拟目录     虚拟目录是指在站点下建立一个虚拟子目录 ...

  2. ASP.NET网站中获取当前虚拟目录的应用程序目录的方法(转)

    [原创]ASP.NET网站中获取当前虚拟目录的应用程序目录的方法 ASP.NET网站中获取当前虚拟目录的应用程序目录的方法1.问题描述:有时候,某个网页控件会被不同目录下文件使用,此时如果该控件中有一 ...

  3. 导出IIS Log列表,导出站点下虚拟目录列表

    Add-Type -AssemblyName System.Web import-module webadministration $ip = (gwmi Win32_NetworkAdapterCo ...

  4. iis虚拟目录或应用程序不继承父站点的web.config配置信息

    A为主站点 B为A的应用程序站点 再A的web.config中对不想继承的节点用location 套起来.如下: <location path="." allowOverri ...

  5. IIS6中给Framework2,。0站点的虚拟目录(2.0版本)下发布Web API项目(4.0版本)问题处理

    Web-API项目以虚拟目录形式部署到IIS6/IIS7 若原有站点为Framework2.0版本,在此站点(或虚拟目录站点)下,新增API虚拟目录,然后选择Framework4.0版本,IIS6和I ...

  6. C# 获取IIS站点及虚拟目录信息

    using System; using System.DirectoryServices; using System.Collections.Generic; using System.Text; n ...

  7. IIS中ASP.NET虚拟目录不继承主站点web.config设置的办法(转载)

    ASP.NET提供了强大的Web.config来配置网站,一般来说一个网站只有一个根目录下的Web.config文件,有时候我们希望子目录有着不同的权限或者参数设置,则可以在相应子目录增加一个Web. ...

  8. [php]修改站点的虚拟目录

    wamp默认的站点的目录是www的目录,可以修改appache的httpd.conf文件来修改目录,修改方法如下: 1. <Directory "D:/SoftWare/wamp/ww ...

  9. 创建虚拟目录失败,必须为服务器名称指定“localhost”?看进来!!

    没废话,直接讲! 关于微信开发过程,远程调试后,再次打开vs出现项目加载失败的解决办法! 上图: 这图应该不陌生,你肯定打开iis把绑定的域名给干掉了.这个提示很坑人,简直就是坑爹!!!fck!! 来 ...

随机推荐

  1. bzoj1968

    题解: 显然每一个数对答案的贡献为n/i 代码: #include<bits/stdc++.h> using namespace std; int n; int main() { scan ...

  2. information_schema

    views 视图表,查看当前数据库有哪些视图 select table_catalog,table_schema,table_name,is_updatable,definer,security_ty ...

  3. react与vue的对比

    模板: Vue Vue应用的默认选项是把markup放在HTML文件中. 数据绑定表达式采用的是和Angular相似的mustache语法,而指令(特殊的HTML属性)用来向模板添加功能. React ...

  4. 线程queue与进程queue

    进程queue: from multiprocessing import Queue,Process def func(qq): qq.put('function:我要放数据,给你来取...') if ...

  5. Android : 获取声卡信息的测试代码

    完整的编译包(android平台): 链接:http://pan.baidu.com/s/1qXMTT7I 密码:2bow /* * ALSA parameter test program * * C ...

  6. 关于Java课堂实验中的一些总结(Scanner)

    import java.util.Scanner; 这个头文件是java里面用来输入东西的,就相当于c++里面的iostream输入流...?暂且这么理解吧 然后使用方法:Scanner in = n ...

  7. 未完全弄懂的题的题51nod1532

    转载自:https://blog.csdn.net/luricheng/article/details/527520941352 集合计数 基准时间限制:1 秒 空间限制:131072 KB 分值: ...

  8. Oracle备份

    今天被吊,特来学习备份. https://blog.csdn.net/zhaiqi618/article/details/5616215 https://www.cnblogs.com/yingpp/ ...

  9. 『翻译』Access USB Devices on the Web

    https://developers.google.com/web/updates/2016/03/access-usb-devices-on-the-web Access USB Devices o ...

  10. 框架:Intellij搭建Spring框架

    第二章.Intellij搭建Spring框架 前提条件:jdk.jre已经安装完成 方法一.intellij下载jar 附:自带的jar的版本为4.3[2018/11/22] 第一步:选择File&g ...