Is there a .NET Library or API to interact with/Edit the IIS Metabase?

☆樱花仙子☆ 提交于 2019-12-21 19:59:07

问题


...or am I stuck rolling my own "XML chopping" functions. I'd like to create a small tasktray app so I can quickly re-point a Virual Directory to one of several of folders on my harddisk.

Bit of background:

I have 3 different svn branches of our code base on my dev machine.

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

Our app integrates with a 3rd party CMS which I've installed at

http://localhost/cms/

In order to work our app has to live at the same root directory. so:

http://localhost/app/

Depending on the branch I'm working on, I'm re-pointing the /app/ directory to one of the 3 paths listed above by going into IIS Manager. Just thought it'd be handy to have a quick-app to do it for me.


回答1:


Ok...this isn't a tray app but you can run it from the command line. Just change the physical paths as necessary:

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;
        }
      }
    }
  }
}

Then run as in:

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

etc




回答2:


I haven't used this my self, so I'm not 100% sure it will solve your problem. But take a look at System.DirectoryServices in .NET. It can access IIS.

MSDN help for DirectoryServices




回答3:


Well, for IIS 7, there is a .NET wrapper to enable IIS management via .NET. See this link for details,

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

For previous version of IIS (5 or 6), ADSI and WMI interfaces are provided,

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



来源:https://stackoverflow.com/questions/301438/is-there-a-net-library-or-api-to-interact-with-edit-the-iis-metabase

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!