我正在编写一个小型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
…
有人知道我怎么解决这个问题吗?