C#获取IIS所有站点及虚拟目录和应用程序(包含名称及详细信息)
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所有站点及虚拟目录和应用程序(包含名称及详细信息)的更多相关文章
- IIS - 虚拟目录与应用程序的异同
在Windows 7 IIS7中,对服务器建立站点后,有二种添加子站点的方式 A. 虚拟目录 B. 应用程序 简单总结下二者之间的异同 A.虚拟目录 虚拟目录是指在站点下建立一个虚拟子目录 ...
- ASP.NET网站中获取当前虚拟目录的应用程序目录的方法(转)
[原创]ASP.NET网站中获取当前虚拟目录的应用程序目录的方法 ASP.NET网站中获取当前虚拟目录的应用程序目录的方法1.问题描述:有时候,某个网页控件会被不同目录下文件使用,此时如果该控件中有一 ...
- 导出IIS Log列表,导出站点下虚拟目录列表
Add-Type -AssemblyName System.Web import-module webadministration $ip = (gwmi Win32_NetworkAdapterCo ...
- iis虚拟目录或应用程序不继承父站点的web.config配置信息
A为主站点 B为A的应用程序站点 再A的web.config中对不想继承的节点用location 套起来.如下: <location path="." allowOverri ...
- IIS6中给Framework2,。0站点的虚拟目录(2.0版本)下发布Web API项目(4.0版本)问题处理
Web-API项目以虚拟目录形式部署到IIS6/IIS7 若原有站点为Framework2.0版本,在此站点(或虚拟目录站点)下,新增API虚拟目录,然后选择Framework4.0版本,IIS6和I ...
- C# 获取IIS站点及虚拟目录信息
using System; using System.DirectoryServices; using System.Collections.Generic; using System.Text; n ...
- IIS中ASP.NET虚拟目录不继承主站点web.config设置的办法(转载)
ASP.NET提供了强大的Web.config来配置网站,一般来说一个网站只有一个根目录下的Web.config文件,有时候我们希望子目录有着不同的权限或者参数设置,则可以在相应子目录增加一个Web. ...
- [php]修改站点的虚拟目录
wamp默认的站点的目录是www的目录,可以修改appache的httpd.conf文件来修改目录,修改方法如下: 1. <Directory "D:/SoftWare/wamp/ww ...
- 创建虚拟目录失败,必须为服务器名称指定“localhost”?看进来!!
没废话,直接讲! 关于微信开发过程,远程调试后,再次打开vs出现项目加载失败的解决办法! 上图: 这图应该不陌生,你肯定打开iis把绑定的域名给干掉了.这个提示很坑人,简直就是坑爹!!!fck!! 来 ...
随机推荐
- Angular4-配置
基于 Angular Quickstart git clone https://github.com/angular/quickstart ng4-quickstart npm i npm start ...
- centos tar 常用
tar命令详解 -c: 建立压缩档案 -x:解压 -t:查看内容 -r:向压缩归档文件末尾追加文件 -u:更新原压缩包中的文件 这五个是独立的命令,压缩解压都要用到其中一个,可以和别的命令连用但只能用 ...
- SharePoint Framework 企业向导(三)
博客地址:http://blog.csdn.net/FoxDave 透视视图:SharePoint在更广泛的SharePoint平台中 SPFx是一个新的模型,附加在已存在的方法上,但是专注于为用 ...
- requery.js使用姿势
最近在看requerjs,现在来总结下自己的收获,有不对的地方,望大家指正! 1.首先介绍下requirejs,引用中文官网http://www.requirejs.cn的一句话,requirejs是 ...
- SQL注入之Sqli-labs系列第二十关(基于头部的cookie POST报错注入)
开始挑战第十八关(Cookie Injection-Error Based- string) 前言: 通常开发人员在开发过程中会特别注意到防止恶意用户进行恶意的注入操作,因此会对传入的参数进行适当的过 ...
- datatables 多一列报错Cannot read property 'sWidth' of undefined(…)/少一列报错Cannot read property 'style' of undefined(…)
datatables 多一列报错Cannot read property 'sWidth' of undefined(…)/少一列报错Cannot read property 'style' of u ...
- Python学习笔记第二十三周(Flask架构)
目录: 一.变量引用 内容: 备注:PyCharm小技巧,comm+alt+l 自动修改格式,comm+alt+return 向上添加新行 一.变量引用 1.url生成 from flask im ...
- Ubuntu 18.04开启TCP网络协议BBR加速的方法(Google BBR 拥塞控制算法)
TCP BBR 是Google给出的一个改良版的tcp网络协议,相当于在已有TCP协议的基础上打了个补丁的意思,这个改良版TCP协议对拥塞控制有很好的支持,对于网络较差的环境有不错的应用场景,当然这里 ...
- 安装 aconda 后Linux的终端界面前部出现(base)字样
aconda 是做什么用的这里就不说了,一般玩Python的都知道这东西,最早接触这东西是因为它把NVIDIA中cuda计算和Python互连的一个库拿下了,是买下来了还是专业,还是唯一合作的也就记不 ...
- Oracle密码概要文件,密码过期时间180天修改为3天,相关用户密码是否过期
#Oracle用户密码,概要文件修改测试 #默认的用户使用概要文件,默认概要文件密码过期时间参数180天,修改为3天,对于老的用户来说,是密码过期,还是未发生改变, 对于新用户来说,新设置的密码过期时 ...