Active Directory, enumerating user's groups, COM exception

后端 未结 3 686
盖世英雄少女心
盖世英雄少女心 2021-01-15 18:00

while enumerating current user\'s groups through AD .NET API I sometimes get

COMException: Unknown error (0x80005000)

Here\'s my code :

相关标签:
3条回答
  • 2021-01-15 18:16

    Try using

    var context = new PrincipalContext(ContextType.Domain, "yourcompany.com", "DC=yourcompany,DC=com", ContextOptions.Negotiate);
    

    With the ContextOption set to Negotioate the client is authenticated by using either Kerberos or NTLM so even if the user name and password are not provided the account management API binds to the object by using the security context of the calling thread.

    0 讨论(0)
  • 2021-01-15 18:17

    0x80005000 = E_ADS_BAD_PATHNAME so you supply an invalid adspath somewhere, maybe you must add LDAP:// prefix or opposit are doing this twice? Set a breakpoint and inspect value...

    EDIT: AdsPath should be a value like "LDAP://CN=Administator,CN=Users,DC=contoso,DC=com", you seem to have a misformed path.

    0 讨论(0)
  • 2021-01-15 18:24

    I had the same problem, I solved it by supplying the domain name when creating the PrincipalContext:

    var domain = new PrincipalContext(ContextType.Domain, Environment.UserDomainName);
    var user = UserPrincipal.FindByIdentity(domain, Environment.UserName);
    
    0 讨论(0)
提交回复
热议问题