C#实现获取IIS站点及虚拟目录信息的方法

本文实例讲述了C#实现获取IIS站点及虚拟目录信息的方法。分享给大家供大家参考。具体如下:

using System;
using System.DirectoryServices;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
  class Program
  {
    static void Main(string[] args)
    {
      DirectoryEntry rootEntry = new DirectoryEntry("IIS://localhost/w3svc");
      int siteID = 1;
      foreach (DirectoryEntry entry in rootEntry.Children)
      {
        if (entry.SchemaClassName.Equals("IIsWebServer", StringComparison.OrdinalIgnoreCase))
        {
          Console.WriteLine("Name: {0}", entry.Name);
          Console.WriteLine("Path: {0}", IISWorker.GetWebsitePhysicalPath(entry));
          Console.WriteLine("ServerBindings: {0}", entry.Properties["ServerBindings"].Value);
          Console.WriteLine();
          DirectoryEntry virEntry = new DirectoryEntry(entry.Path + "/ROOT");
          foreach (DirectoryEntry entryVirtual in virEntry.Children)
          {
            if (entryVirtual.SchemaClassName.Equals("IIsWebVirtualDir", StringComparison.OrdinalIgnoreCase))
            {
              Console.WriteLine("SchemaClassName: {0}", entryVirtual.SchemaClassName);
              Console.WriteLine("Name: {0}", entryVirtual.Name);
              Console.WriteLine("Path: {0}", entryVirtual.Properties["Path"].Value);
              Console.WriteLine();
            }
          }
          int ID = Convert.ToInt32(entry.Name);
          if (ID >= siteID)
          {
            siteID = ID + 1;
          }
        }
      }
    }
  }
  public class IISWorker
  {
    /// <summary>
    /// 得到网站的物理路径
    /// </summary>
    /// <param name="rootEntry">网站节点</param>
    /// <returns></returns>
    public static string GetWebsitePhysicalPath(DirectoryEntry rootEntry)
    {
      string physicalPath = "";
      foreach (DirectoryEntry childEntry in rootEntry.Children)
      {
        if ((childEntry.SchemaClassName == "IIsWebVirtualDir") && (childEntry.Name.ToLower() == "root"))
        {
          if (childEntry.Properties["Path"].Value != null)
          {
            physicalPath = childEntry.Properties["Path"].Value.ToString();
          }
          else
          {
            physicalPath = "";
          }
        }
      }
      return physicalPath;
    }
  }
}

希望本文所述对大家的C#程序设计有所帮助。

(0)

相关推荐

  • c# 解决IIS写Excel的权限问题

    具体配置方法如下: 1:在服务器上安装office的Excel软件. 2:在"开始"->"运行"中输入dcomcnfg.exe启动"组件服务" 3:依次双击"组件服务"->"计算机"->"我的电脑"->"DCOM配置" 4:在"DCOM配置"中找到"Microsoft Excel 应用程序",在它上面点击

  • C#实现创建,删除,查找,配置虚拟目录实例详解

    本文实例讲述了C#实现创建,删除,查找,配置虚拟目录的方法.分享给大家供大家参考.具体如下: #region<<虚拟目录>> /// <summary> /// 创建虚拟目录 /// </summary> /// <param >虚拟目录别名</param> /// <param >内容所在路径</param> public static bool CreateVirtualDirectory(string w

  • 用C#操纵IIS(代码)

    using System;  using System.DirectoryServices;  using System.Collections;  using System.Text.RegularExpressions;  using System.Text;  /**   * @author 吴海燕   * @email  wuhy80-usual@yahoo.com   * 2004-6-25 第一版   */   namespace Wuhy.ToolBox  {       /// 

  • C#创建IIS虚拟目录的方法

    本文实例讲述了C#创建IIS虚拟目录的方法.分享给大家供大家参考.具体分析如下: DirectoryEntry是.Net给我们的一大礼物,他的名字我们就知道他的功能--目录入口.使用过ADSI的人都知道操作IIS,WinNT这些时,我们还需要提供他们的Path,操作IIS时,这个Path的格式为: 复制代码 代码如下: IIS://ComputerName/Service/Website/Directory ComputerName:即操作的服务器的名字,可以是名字也可以是IP,经常用的就是lo

  • C#操作IIS方法集合

    C# 操作IIS方法集合 如果在win8,win7情况下报错:未知错误(0x80005000) ----见http://www.jb51.net/article/72881.htm using System; using System.Collections; using System.Collections.Generic; using System.DirectoryServices; using System.Linq; using System.Net; using System.Tex

  • C#修改IIS站点framework版本号的方法

    本文实例讲述了C#修改IIS站点framework版本号的方法.分享给大家供大家参考.具体如下: 使用ASP.NET IIS 注册工具 (Aspnet_regiis.exe)可以方便地更新 ASP.NET 应用程序的脚本映射,使其指向与该工具关联的 ASP.NET ISAPI 版本. 关于ASP.NET IIS 注册工具的更详细的内容,请参考MSDN. 在控制台上我们使用下面的命令可以修改一个虚拟目录的Asp.Net版本: 复制代码 代码如下: Aspnet_iis.exe –s path 我们

  • C#操作IIS程序池及站点的创建配置实现代码

    首先要对Microsoft.Web.Administration进行引用,它主要是用来操作IIS7: using System.DirectoryServices;using Microsoft.Web.Administration; 1:首先是对本版IIS的版本进行配置: 复制代码 代码如下: DirectoryEntry getEntity = new DirectoryEntry("IIS://localhost/W3SVC/INFO");            string V

  • c#操作iis根目录的方法

    本文实例讲述了c#操作iis根目录的方法.分享给大家供大家参考.具体实现方法如下: using System; using System.DirectoryServices; using System.Collections; namespace IISManagement { /// <summary> /// IISManager 的摘要说明. /// </summary> public class IISManager { //定义需要使用的 private string _

  • C#实现获取IIS站点及虚拟目录信息的方法

    本文实例讲述了C#实现获取IIS站点及虚拟目录信息的方法.分享给大家供大家参考.具体如下: using System; using System.DirectoryServices; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { DirectoryEntry rootEntr

  • IOS获取当前版本号 Bundle ID等信息的方法详解

     IOS获取当前版本号 Bundle ID等信息的方法 1:获取bundle Id信息:[[NSBundle mainBundle]bundleIdentifier]: 2:获取版本号:[[[NSBundle mainBundle]infoDictionary] objectForKey:@"CFBundleShortVersionString"]; 3:获取build号:[[[NSBundle mainBundle]infoDictionary] objectForKey:@&quo

  • php获取发送给用户的header信息的方法

    本文实例讲述了php获取发送给用户的header信息的方法.分享给大家供大家参考.具体分析如下: headers_list函数没有参数,并返回一个数组.返回的数组包含一个数字索引表,包含了要发送给客户端的header信息 <?php header("Expires: Sat, 12 Dec 1989 05:30:00 GMT"); echo "This is some output.<br />"; echo "Headers sent

  • Android获取手机SIM卡运营商信息的方法

    本文实例讲述了Android获取手机SIM卡运营商信息的方法,对于Android程序设计有非常实用的价值.分享给大家供大家参考之用.具体方法如下: 主要功能代码如下: /** * 获取SIM卡运营商 * * @param context * @return */ public static String getOperators(Context context) { TelephonyManager tm = (TelephonyManager) context .getSystemServic

  • Android开发获取系统中已安装程序信息的方法

    本文实例讲述了Android开发获取系统中已安装程序信息的方法.分享给大家供大家参考,具体如下: public class AppInfoParser { private static String tag = "AppInfoParser"; public static List<AppInfo> getAppInfos(Context context){ //首先获取到包的管理者 PackageManager packageManager = context.getPa

  • ASP.NET对IIS中的虚拟目录进行操作的代码

    复制代码 代码如下: //假如虚拟目录名为"Webtest",先在项目中引用 //System.DirectoryServices.dll,再 using System.DirectoryServices; protected System.DirectoryServices.DirectoryEntry dirroot; 1.添加新的虚拟目录 复制代码 代码如下: DirectoryEntry newVirDir = dirroot.Children.Add("Webtes

  • win2003服务器中创建Web网站虚拟目录的图文方法

    有两种方式可以实现这一目标,一种方式是在网站主目录中新建一个子目录,并把相关内容复制到这个目录中.另一种方式就是创建虚拟目录,虚拟目录既可以是本地磁盘中的任何一个目录,也可以是网络中其他计算机中的目录.相对而言,创建子目录的方式更安全高效. 虚拟目录需要在主目录的基础上进行创建,创建步骤如下所述: 第1步,在开始菜单中依次单击"管理工具"→"Internet信息服务(IIS)管理器"菜单项,打开"Internet 信息服务(IIS)管理器"窗口.

  • asp.net Cookie跨域、虚拟目录等设置方法

    Cookie有三个属性需要注意一下: . Domain 域 . Path 路径 . Expires 过期时间 跨域操作需要设置域属性: Response.Cookies("MyCookie").Domain = "jb51.net"; (这里指的是泛域名) 这样在其它二级域名下就都可以访问到了, ASP 和 ASP.NET 测试通过 虚拟目录下访问: 我在ASP端做了下测试,.NET的没试, 如果不指定Path属性, 不同虚拟目录下Cookie无法共享 将Respo

  • 解析在apache里面给php写虚拟目录的详细方法

    步骤1.首先打开AppServ\Apache2.2\conf里面的httpd.conf文件.在里面找到:LoadModule rewrite_module modules/mod_rewrite.so这行,将他前面的"#"去掉.步骤2.找到:Include conf/extra/httpd-vhosts.conf将他前面的"#"去掉.(很关键)然后接着再找到:<Directory />    Options FollowSymLinks ExecCGI

  • Serv-U中虚拟目录的设置方法(文字+图文)

    Serv-U虚拟目录设置文字版: 一.用Serv-U时,如果使用虚拟路径映射(虚拟目录),那么就只需设定某个文件夹为主目录,然后把想要分享文件映射到该目录下,可以有效提高利用效率,好处不言自明:不用每次把文件内容复制到主目录下.访客通过FTP就可以打开主人设定的文件资料--即使是在不同盘符下的. 要增加虚拟目录,以用户(admin)的主目录为F:\admin,想要能通过ftp://IP/admin的格式能访问到在E:\Download\中的内容,则需要为它添加虚拟目录.操作步骤如下: (1)在管

随机推荐