【问题标题】:Impersonation exception invoking DirectoryEntry.Invoke method调用 DirectoryEntry.Invoke 方法的模拟异常
【发布时间】:2011-10-24 16:25:53
【问题描述】:

我在尝试使用 System.DirectoryServices.DirectoryEntry.Invoke() 方法回收远程 IIS 服务器上的应用程序池时遇到了一个令人沮丧的问题。

基本上下文是两台客户端机器和一台 IIS 7.0 服务器机器(Windows 2008 Server)myServer,它们都在同一个 Windows 域中。我想在客户端机器上运行代码 回收 IIS 服务器上的 AppPool。

下面是相关代码sn-p:

DirectoryEntry directoryEntry = new DirectoryEntry("IIS://myServer/W3SVC/AppPools/SomeAppPool", domainUserid, password, AuthenticationTypes.Secure);

directoryEntry.Invoke("回收", null);

在一台客户端机器上,代码成功运行,但在另一台客户端机器上,代码引发了与模拟相关的异常(见下文)。 我在两台客户端机器上都以相同的域用户身份登录,并在代码中使用相同的域用户信息。

我检查了服务器端事件查看器和其他日志,看看服务器上处理请求的方式是否存在明显差异,并进行了大量谷歌搜索但没有成功。

任何人都可以提供线索,了解要查找什么或我可以运行哪些诊断程序(在客户端计算机或服务器计算机上)以确定发生这种情况的原因吗?

感谢您的帮助!马丁

2011-08-10 22:35:39,478 [10] 警告 - ActionRestartIIS:异常重新启动 IIS System.Reflection.TargetInvocationException:异常已被 由调用的目标抛出。 ---> System.Runtime.InteropServices.COMException (0x80070542):未提供所需的模拟级别, 或提供的模拟级别无效。 (来自 HRESULT 的异常:0x80070542) --- 内部异常堆栈跟踪结束 --- 在 System.DirectoryServices.DirectoryEntry.Invoke(String methodName, Object[] args)

【问题讨论】:

  • 在回答自己问题的优良传统中,这是我学到的。我修改了我的代码以使用 System.Management 类,这些似乎跨域工作得更好。示例代码如下:

标签: iis impersonation


【解决方案1】:

在回答自己问题的优良传统中,这就是我学到的东西。我修改了我的代码以使用 System.Management 类,这些似乎跨域工作得更好。示例代码如下:

ConnectionOptions connectionOptions = new ConnectionOptions();

connectionOptions.Authority = "ntlmdomain:" + this.domain;

connectionOptions.Username = this.username; connectionOptions.Password = this.password;

connectionOptions.EnablePrivileges = true;

connectionOptions.Authentication = AuthenticationLevel.PacketPrivacy;

ManagementScope managementScope = new ManagementScope(@"\" + this.iisserver + @"\root\microsoftiisv2", connectionOptions);

managementScope.Connect();

ManagementObject appPool = new ManagementObject(managementScope, new ManagementPath("IISApplicationPool.Name='W3SVC/AppPools/" + apppool + "'"), null);

appPool.InvokeMethod("回收", null, null);

【讨论】:

    猜你喜欢
    • 2015-10-09
    • 2018-07-22
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-12
    • 1970-01-01
    相关资源
    最近更新 更多