代码之家  ›  专栏  ›  技术社区  ›  kitsune

ADSI/IIS管理和ASP.NET模拟

  •  0
  • kitsune  · 技术社区  · 16 年前

    我正在编写一个小型Web应用程序,它允许我管理网络上不同服务器上的几个IIS安装。我们没有域控制器。

    我编写了一个小型模拟控制器,它使用win32 api及其logonuser方法。然后,我使用System.DirectoryServices和IIS ADSI提供程序创建一个新站点。

    我有以下程序(用明文字符串交换一些值以提高可读性):

                if (impersonationSvc.ImpersonateValidUser("Administrator@SRV6", String.Empty, "PASSWORD))
                {
    
    
                string metabasePath = "IIS://" + server.ComputerName + "/W3SVC";
                DirectoryEntry w3svc = new DirectoryEntry(metabasePath, "Administrator", "PASSWORD");
    
                string serverBindings = ":80:" + site.HostName;
                string homeDirectory = server.WWWRootNetworkPath + "\\" + site.FolderName;
    
    
                object[] newsite = new object[] { site.Name, new object[] { serverBindings }, homeDirectory };
    
                object websiteId = (object)w3svc.Invoke("CreateNewSite", newsite);
                int id = (int)websiteId;
    
                impersonationSvc.UndoImpersonation();
            }
    

    当我使用承载Web应用的服务器(SRV6)时,此例程工作。将创建新网站。

    例如,如果我使用srv5,我们网络上的另一个服务器(没有域),impersonatevaliduser工作,则会创建目录entry,但w3svc.invoke失败,并出现以下错误:

    [ComException(0x80070005):拒绝访问]

    System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) +377678
    System.DirectoryServices.DirectoryEntry.Bind() +36
    System.DirectoryServices.DirectoryEntry.get_NativeObject() +31
    System.DirectoryServices.DirectoryEntry.Invoke(String methodName, Object[] args) +53
    

    有人知道我怎么解决这个问题吗?

    2 回复  |  直到 16 年前
        1
  •  1
  •   Moose    16 年前

    在此情况下不能使用模拟。您模拟的帐户需要本地计算机上的登录权限。

    如果您的Web服务器不是域的一部分,我认为TANT102的Web服务思想是您唯一的出路。

        2
  •  0
  •   sisve    16 年前

    我将查看srv5的事件日志,以检查连接到该服务器时使用了哪些特权。您可能需要更改组策略以将失败记录在安全日志中。

    在服务器上设置WebServices听起来更容易,最好是受登录和/或IP限制的保护,这样做可以完成这些操作。