ネットワーク上のさまざまなサーバーにインストールされている複数の IIS を管理できる小さな Web アプリケーションを作成中です。ドメインコントローラーはありません。
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 が機能し、DirectoryEntry が作成されますが、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
...
どうすればこれを解決できるか知っている人はいますか?