1

アクティブ ディレクトリ、Windows 8

ユーザー「xxx」でログオンし、そのようなコードでアプリケーションを実行した場合:

//WindowsIdentity.GetCurrent().Name - is "MyDomain\xxx";
var connectionOptions = new ConnectionOptions
{
  EnablePrivileges = true,
  Impersonation = ImpersonationLevel.Impersonate
};
var scope = new ManagementScope(
  string.Format("\\\\{0}\\root\\CIMV2", computerName),
  connectionOptions);
scope.Connect();

それはうまくいきます。

ただし、同じマシンの IIS でこのコードを実行すると、例外が発生します。

// WindowsIdentity.GetCurrent().Name - is "NT AUTHORITY\SYSTEM" or "IIS APPPOOL\DefaultAppPool", tryed both
var windowsIdentity = User.Identity as WindowsIdentity;
if (windowsIdentity != null)
{
  using (windowsIdentity.Impersonate())
  {
    // WindowsIdentity.GetCurrent().Name - is "MyDomain\xxx";
    var connectionOptions = new ConnectionOptions
    {
      EnablePrivileges = true,
      Impersonation = ImpersonationLevel.Impersonate
    };
    var scope = new ManagementScope(
      string.Format("\\\\{0}\\root\\CIMV2", computerName),
      connectionOptions);
    scope.Connect(); 
    // throws exception "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"
    // my other code here        
  }
}

使用された Windows 認証:

<authentication mode="Windows" />
<identity impersonate="false" />

AppPool を ApplicationPoolIdentity および System として実行しようとしました。AppPool に「オペレーティング システムの一部として機能する」権限を付与しようとしました。結果は同じで、常に「アクセスが拒否されました」というメッセージが表示されました。

なぜこの例外があるのですか? 偽装するか、AppPool にいくつかの権限を付与する以外に何かする必要がありますか?

4

0 に答える 0