C# を使用してリモートで IIS アプリケーション プール ユーザーをローカル ユーザー グループに追加しようとしていますが、問題が発生しています。
以下の2つのアプローチを試しました。
// This results in a ArgumentNullException because user is never set
using (PrincipalContext pc = new PrincipalContext(ContextType.Machine, serverName))
{
UserPrincipal user = UserPrincipal.FindByIdentity(pc, String.Format(@"IIS APPPOOL\{0}", rootApplicationPoolName));
GroupPrincipal myGroup = GroupPrincipal.FindByIdentity(pc, "mygroupname");
myGroup.Members.Add(user);
myGroup.Save();
}
また:
// This results in a NoMatchingPrincipalException saying the user could not be found
using (PrincipalContext pc = new PrincipalContext(ContextType.Machine, serverName))
{
GroupPrincipal myGroup= GroupPrincipal.FindByIdentity(pc, "mygroupname");
myGroup.Members.Add(pc, IdentityType.Name, String.Format(@"IIS APPPOOL\{0}", appPoolName));
myGroup.Save();
}
このユーザーを手動でグループに追加すると、問題なく機能します。
私は何が欠けていますか?