正文

DirectoryEntry.Properties遍历IIS属性(1)2009-07-19 19:59:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/xman/45364.html

分享到:

一.平台:Windows XP SP3+ IIS 5.1 + Visual Studio 2005

.NET框架下,System.DirectoryServices命名空间中的DirectoryEntry提供了活动目录组件管理功能,它调用ADSI操作IIS

二.DirectoryEntry.Properties遍历IIS Web虚拟目录和Ftp虚拟目录属性

using System;

using System.Collections.Generic;

using System.Text;

using System.DirectoryServices;

 

namespace IISVirDirProperties

{

    class Program

    {

        static void Main(string[] args)

        {

            try

            {

                Console.WriteLine("请输入欲查询的虚拟目录类型:");

                Console.WriteLine("0代表IIS Web虚拟目录");

                Console.WriteLine("1代表IIS FTP虚拟目录");

 

                string SVCType, VirDirType;

                string strVirDirType  = Console.ReadLine();

 

                if(strVirDirType == "0")

                {

                    SVCType = "W3SVC";

                    VirDirType = "IIsWebVirtualDir";

                }

                else if(strVirDirType == "1")

                {

                    SVCType = "MSFTPSVC";

                    VirDirType = "IIsFtpVirtualDir";

                }

                else

                {

                    Console.WriteLine("输入有误,只能输入01");

                    Console.ReadKey();

                    return;

                }

 

                string RootPath = "IIS://localhost/" + SVCType + "/1/ROOT";

                DirectoryEntry RootDE = new DirectoryEntry(RootPath);

                DirectoryEntry DE = null;

 

                Console.WriteLine("请输入欲查询的虚拟目录名称:");

                string strVirDir = Console.ReadLine();

               

                if(string.IsNullOrEmpty(strVirDir)) // 为空,查询默认站点

                {

                    DE = RootDE;

                    Console.WriteLine("默认站点的属性如下:\n");

                }

                else // 非空,查询具体站点

                {

                    string WebSitePath = RootPath + "/" + strVirDir;

                    if(DirectoryEntry.Exists(WebSitePath))

                    {

                        DE = RootDE.Children.Find(strVirDir, VirDirType);

                        Console.WriteLine("默认站点|{0}属性如下:\n",strVirDir);

                    }

                    else

                    {

                        Console.WriteLine("你所查询的虚拟目录不存在!");

                        Console.ReadKey();

                        return;

                    }                   

                }

                foreach (string elmentName in DE.Properties.PropertyNames)

                {

                    PropertyValueCollection valueCollection = DE.Properties[elmentName];

                    for (int i = 0; i < valueCollection.Count; i++)

                    {

                        Console.WriteLine(elmentName + "[" + i.ToString() + "] =" + valueCollection[i].ToString());

                    }

                }

            }

            catch(Exception e)

            {

                Console.WriteLine(e.Message);

            }

 

            Console.ReadKey();

        }

    }

}

IIS6.0中,可右击网站(FTP站点)à默认网站(默认FTP站点)àtestà所有任务à将配置保存到一个XML文件,打开XML文件可以看到

<configuration> +<MBProperty></configuration>

其中MBPropertyMetaBase详细属性信息。

下一篇DirectoryEntry.Properties遍历IIS属性(2)

阅读(5817) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册