おはようございます、
Active Directory でユーザーを検索しようとしていますが、次の例外が発生します。
{System.SystemException} = {"Unable to cast object of type 'System.DirectoryServices.AccountManagement.GroupPrincipal' to type
'System.DirectoryServices.AccountManagement.UserPrincipal'."}
私のコードは次のとおりです。過去に機能していたようですが、何が変わったのかわかりません。私は凝視してデバッグしてきましたが、問題を見つけることができません。助けてください。
using (PrincipalContext ctx = new PrincipalContext(
ContextType.Domain, host, uContext))
{
if (ctx != null)
{
using(UserPrincipal p = UserPrincipal.FindByIdentity(ctx,IdentityType.SamAccountName, username))
{
ここで、uContext は: "CN=Users,DC=my,DC=eh,DC=tech,DC=com"
、host は: my.eh.tech.com
、ユーザー名は:madamzuzu です。
ADでユーザーを探すと、次のように正しく表示されますDN:CN=madamzuzu;CN=Users,DC=my,DC=eh,DC=tech,DC=com
「グループプリンシパル」がどこから来ているのか理解できませんか?