-1

ドメイン DomainA のユーザー User001 で、パスワード Pass001 でログインしています。

私はこのコードを使用します

//var principalContext = new PrincipalContext(
    //ContextType.Domain,
    //"DomainA",
    //"User001",
    //"Pass001");

var principalContext = new PrincipalContext(
    ContextType.Domain,
domain, 
    userName,
    password);
var userPrincipal = new UserPrincipal(principalContext);

そしてuserPrincipal 常に NULL です。

修正方法は?

4

1 に答える 1

1

どういうわけか、私が見つけたこのコードは正常に動作しています...

 using (var context = new PrincipalContext(ContextType.Domain))
            {
                using (UserPrincipal principal = UserPrincipal.FindByIdentity(context, userName))
                {
                    var uGroups = principal.GetGroups();
                    foreach (var group in uGroups)
                    {
                        Debug.WriteLine(group.DisplayName);
                    }
                }
            }
于 2013-12-13T11:14:21.987 に答える