2013-08-30 92 views
0

我正在嘗試在ADAM中重置用戶密碼。對於我使用Accountmanagement namesapce用c#重置ADAM用戶密碼

我的嘗試:

PrincipalContext rootPrincipalContext; 
LdapConnection objLdapconnection; 
rootPrincipalContext = new PrincipalContext(ContextType.ApplicationDirectory, host, baseDN, ContextOptions.Negotiate, username, password); 
LdapDirectoryIdentifier identifier = new LdapDirectoryIdentifier(host, Convert.ToInt32(port)); 
NetworkCredential credential = new NetworkCredential(username, password); 
LdapConnection ldapCon = new LdapConnection(identifier, credential); 
ldapCon.AuthType = AuthType.Negotiate; 
objLdapconnection = ldapCon; 

密碼重置:

UserPrincipal existingUsr = UserPrincipal.FindByIdentity(rootPrincipalContext, IdentityType.DistinguishedName, "cn=" + inputName + ",ou=gslab,dc=starfish"); 

existingUsr.SetPassword(userPassvalue); this lines throws exception "directory property can not be found" 

我已經檢查沒有字符串是空的,也試過contextOption.secureSocketlayer但沒有作品

我需要提供加密密碼嗎?還是我需要設置任何屬性?提前致謝。

回答

0

那麼我得到了解決方案。只要刪除

ContextOptions.Negotiate 

而實例化rootprincipalContext

並在SetPassword()之前使用ExpirePasswordNow()方法。