是否有.NET库或API与IIS Metabase交互/编辑IIS Metabase?

时间:2008-11-19 10:10:56

标签: .net iis api metabase

...或者我不得不继续推行自己的“XML斩波”功能。我想创建一个小型任务栏应用程序,以便我可以快速将虚拟目录重新指向我硬盘上的几个文件夹之一。

背景:

我的dev机器上有3个不同的svn分支。

Current Production Branch    ( C:\Projects\....\branches\Prod\ )
Next Release Canidate Branch ( C:\Projects\....\branches\RCX\ )
Trunk                        ( C:\Projects\....\trunk\ )

我们的应用程序与我在

安装的第三方CMS集成
http://localhost/cms/

为了工作,我们的应用必须住在同一个根目录。这样:

http://localhost/app/

根据我正在处理的分支,我通过进入IIS管理器将/app/目录重新指向上面列出的3个路径之一。只是觉得有一个快速应用程序为我做这件事很方便。

3 个答案:

答案 0 :(得分:3)

好的...这不是托盘应用程序,但您可以从命令行运行它。只需根据需要更改物理路径:

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

namespace Swapper
{
  class Program
  {
    static void Main(string[] args)
    {
      using (DirectoryEntry appRoot = 
               new DirectoryEntry("IIS://Localhost/W3SVC/1/root/app"))
      {
        switch (args[0].ToLower())
        {
          case "prod":
            appRoot.Properties["Path"].Value = @"e:\app\prod";
            appRoot.CommitChanges();
            break;

          case "rcx":
            appRoot.Properties["Path"].Value = @"e:\app\rcx";
            appRoot.CommitChanges();
            break;

          case "trunk":
            appRoot.Properties["Path"].Value = @"e:\app\trunk";
            appRoot.CommitChanges();
            break;

          default:
            Console.WriteLine("Don't know");
            break;
        }
      }
    }
  }
}

然后按以下方式运行:

C:\>swapper prod
C:\>swapper rcx

答案 1 :(得分:1)

我没有用过这个我自己,所以我不是百分百肯定会解决你的问题。但是看看.NET中的System.DirectoryServices。它可以访问IIS。

MSDN help for DirectoryServices

答案 2 :(得分:1)

那么,对于IIS 7,有一个.NET包装器可以通过.NET启用IIS管理。有关详细信息,请参阅此链接

http://learn.iis.net/page.aspx/165/how-to-use-microsoftwebadministration/

对于以前版本的IIS(5或6),提供了ADSI和WMI接口,

http://msdn.microsoft.com/en-us/library/ms525885.aspx

相关问题