无法验证新创建的用户

时间:2011-06-16 15:48:19

标签: c# directoryservices account-management

  
  using(PrincipalContext cntx = new PrincipalContext(
        ContextType.Domain, "blah.corp.net:389", "OU=customers,OU=web,CN=blah,CN=corp,CN=net", 
        ContextOptions.Negotiate, "Domin\Admin", "{Password}")){
        string password = "PPaass00!!";
        UserPrincipal p = new UserPrincipal(cntx);
        p.SamAccountName = "GuestUser";
        p.PasswordNeverExpires = true;
        p.Enabled = true;
        p.SetPassword(password);
        p.Save();
        bool b = cntx.ValidateCredentials("GuestUser", password); //where b always false
    }

我不明白为什么b总是假的。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

虽然我不知道您问题的答案,但您是否尝试过这种方法?

PrincipalContext cntx = new PrincipalContext(ContextType.Domain, 
    "blah.corp.net:389", 
    "OU=customers,OU=web,CN=blah,CN=corp,CN=net",ContextOptions.Negotiate, 
    "Domin\GuestUser", password)

在它周围放置一个try / catch,看看它是否在连接时抛出异常。

相关问题