イントラネット上で実行されるASP.NETアプリケーションがあります。本番環境では、ドメインコンテキストからユーザーを取得し、名前と名前(UserPrincipal.GivenNameおよびUserPrincipal.Surname)を含む多くの情報にアクセスできます。
私たちのテスト環境は本番ドメインの一部ではなく、テストユーザーはテスト環境にドメインアカウントを持っていません。そこで、それらをローカルマシンユーザーとして追加します。スタートページを参照すると、資格情報の入力を求められます。次のメソッドを使用してUserPrincipalを取得します
public static UserPrincipal GetCurrentUser()
{
UserPrincipal up = null;
using (PrincipalContext context = new PrincipalContext(ContextType.Domain))
{
up = UserPrincipal.FindByIdentity(context, User.Identity.Name);
}
if (up == null)
{
using (PrincipalContext context = new PrincipalContext(ContextType.Machine))
{
up = UserPrincipal.FindByIdentity(context, User.Identity.Name);
}
}
return up;
}
ここでの問題は、ContextType == MachineのときにUserPrinicipalが取得されたときに、GivenNameやSurnameなどのプロパティを取得できないことです。ユーザー(Windows Server 2008)を作成するときにこれらの値を設定する方法はありますか、それとも別の方法でこれを行う必要がありますか?