1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.DirectoryServices;
  10. using System.Diagnostics;
  11.  
  12. namespace WindowsFormsApplication13
  13. {
  14. public partial class Form1 : Form
  15. {
  16. public Form1()
  17. {
  18. InitializeComponent();
  19. }
  20.  
  21. void ShowEntry(DirectoryEntry entry)
  22. {
  23. foreach (DirectoryEntry childEntry in entry.Children)
  24. {
  25. if (childEntry.SchemaClassName == "IIsWebServer")
  26. {
  27. Debug.Print(childEntry.SchemaClassName + ":" + childEntry.Properties["ServerComment"].Value.ToString());
  28. Debug.Print("*********************Start*************************");
  29. foreach (var name in childEntry.Properties.PropertyNames)
  30. {
  31. Debug.Print(name + ":" + childEntry.Properties[name.ToString()].Value);
  32. }
  33. Debug.Print("*********************End*************************");
  34. }
  35. else if (childEntry.SchemaClassName == "IIsWebVirtualDir")
  36. {
  37. Debug.Print(childEntry.SchemaClassName + ":" + childEntry.Name);
  38. Debug.Print("*********************Start*************************");
  39. foreach (var name in childEntry.Properties.PropertyNames)
  40. {
  41. Debug.Print(name + ":" + childEntry.Properties[name.ToString()].Value);
  42. }
  43. Debug.Print("*********************End*************************");
  44. }
  45. else
  46. {
  47. //Debug.Print(childEntry.SchemaClassName);
  48. }
  49. ShowEntry(childEntry);
  50. }
  51. }
  52.  
  53. private void Form1_Load(object sender, EventArgs e)
  54. {
  55. ShowEntry(new DirectoryEntry("IIS://localhost/w3svc"));
  56. }
  57. }
  58. }

获取IIS树型目录:

  1. public class SiteInfo
  2. {
  3. public string Name { get; set; }
  4. public string Path { get; set; }
  5. public bool IsApp { get; set; }
  6. public List<SiteInfo> Children { get; set; }
  7. }
  8.  
  9. List<SiteInfo> getSiteList(DirectoryEntry entry)
  10. {
  11. var result = new List<SiteInfo>();
  12. foreach (DirectoryEntry childEntry in entry.Children)
  13. {
  14. var sites = getSiteList(childEntry);
  15. if (childEntry.SchemaClassName == "IIsWebServer")
  16. {
  17. var site = new SiteInfo();
  18. site.Name = childEntry.Properties["ServerComment"].Value.ToString();
  19. site.Path = sites[].Path;
  20. site.IsApp = true;
  21. site.Children = new List<SiteInfo>();
  22. foreach (var subSite in sites[].Children)
  23. site.Children.Add(subSite);
  24. result.Add(site);
  25. }
  26. else if (childEntry.SchemaClassName == "IIsWebVirtualDir")
  27. {
  28. var site = new SiteInfo();
  29. site.Name = childEntry.Name;
  30. site.Path = childEntry.Properties["Path"].Value.ToString();
  31. site.Children = sites;
  32. if (childEntry.Properties.Contains("AppRoot")
  33. && childEntry.Properties["AppRoot"].Value != null
  34. && !string.IsNullOrEmpty(childEntry.Properties["AppRoot"].Value.ToString()))
  35. site.IsApp = true;
  36. result.Add(site);
  37. }
  38. }
  39. return result;
  40. }
  1. public List<KeyValuePair<SiteInfo, string>> getFlatSiteList(List<SiteInfo> sites, string parentPadding = "")
  2. {
  3. var result = new List<KeyValuePair<SiteInfo, string>>();
  4. foreach (var site in sites)
  5. {
  6. var currentPrefix = parentPadding == string.Empty ? string.Empty : "└" + parentPadding;
  7. result.Add(new KeyValuePair<SiteInfo, string>(site, currentPrefix + site.Name));
  8. result.AddRange(getFlatSiteList(site.Children, parentPadding + "--"));
  9. }
  10. return result;
  11. }
  12.  
  13. private void Form1_Load(object sender, EventArgs e)
  14. {
  15. var siteList = getSiteList(new DirectoryEntry("IIS://localhost/w3svc"));
  16. var flatSiteList = getFlatSiteList(siteList);
  17. foreach (var list in flatSiteList)
  18. Debug.Print(list.Value);
  19. }

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. LeetCode 回溯法 别人的小结 八皇后 递归

    #include <iostream> #include <algorithm> #include <iterator> #include <vector&g ...

  2. DBProxy 项目全解

    转载自:https://github.com/Meituan-Dianping/DBProxy/blob/master/doc/USER_GUIDE.md#2 1 总体信息        1.1 关于 ...

  3. Array和ArrayList有什么区别?

    Array和ArrayList的区别: 1.Array可以包含基本数据类型和对象类型,而ArrayList只能包含对象类型 2.Array有固定的大小,而ArrayList是动态变化的. 3.Arra ...

  4. SQL-18 查找当前薪水(to_date='9999-01-01')排名第二多的员工编号emp_no、薪水salary、last_name以及first_name,不准使用order by

    题目描述 查找当前薪水(to_date='9999-01-01')排名第二多的员工编号emp_no.薪水salary.last_name以及first_name,不准使用order byCREATE ...

  5. SharePoint online Multilingual support - Settings

    博客地址:http://blog.csdn.net/FoxDave This post will talk about how to enable sharepoint online site mul ...

  6. Install SharePoint 2013 with SP1 on Windows Server 2012 R2 error - This Product requires .NF 4.5

    博客地址:http://blog.csdn.net/FoxDave 最近因为项目需要要搭建SharePoint 2013的开发环境. 准备了Windows Server 2012 R2系统和Sha ...

  7. poj1062(分区间迪杰斯特拉,内含测试数据,一直wa的同学可以进来看看)

    昂贵的聘礼 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 54946   Accepted: 16518 Descripti ...

  8. 2010年腾讯前端面试题学习(jquery,html,css部分)

    看了牛人写的回忆文章,里面有2010年腾讯的前端面试题,里面涉及到不少基础性的问题,js部分已学习,这是jquery,html和css部分,学习一下:) 原文地址:https://segmentfau ...

  9. WebService的一种简单应用方式入门

    1.什么是WebService? WebService即Web服务,简单来讲,他就是一种跨编程语言和跨操作平台的远程调用技术. 2.Web服务: Web服务是基于HTTP和XML的技术:HTTP是互联 ...

  10. winform 异性窗体的实现

    效果图 首先需要在vs里添加控件  AlphaForm.dll 添加完了有这来两个控件 1.把第二个控件拖入窗体里把窗体铺满 2.找一张至少有一个闭合图形的透明图片 设置为AlphaFormTrans ...