PrincipalContext ctx = new PrincipalContext( ContextType.Domain, "fabrikam.com", "CN=Users,DC=fabrikam,DC=com", "administrator", "securelyStoredPassword"); UserPrincipal usr = new UserPrincipal(ctx);usr.Name = "Jim Daly"; usr.Description = "This is the user account for Jim Daly"; usr.EmailAddress = "[email protected]"; usr.SetPassword("securelyStoredPassword"); usr.Save();usr.Dispose(); ctx.Dispose();
if (results != null)
{
DirectoryEntry userEntry = new DirectoryEntry(results.Path, LDAPUser, LDAPPassword);
return new UserInfo(userEntry);
} UserInfo.name=...
UserInfo.Tel=...
...
实际上UserInfo里面的字段赋值都是通过
public string GetPropertyValue(DirectoryEntry propertyEntry,string properties)
{
if (propertyEntry.Properties.Contains(properties))
{
return propertyEntry.Properties[properties][0].ToString();
}
else
{
return String.Empty;
}
}
PrincipalContext ctx = new PrincipalContext(
ContextType.Domain,
"fabrikam.com",
"CN=Users,DC=fabrikam,DC=com",
"administrator",
"securelyStoredPassword"); UserPrincipal usr = new UserPrincipal(ctx);usr.Name = "Jim Daly";
usr.Description = "This is the user account for Jim Daly";
usr.EmailAddress = "[email protected]";
usr.SetPassword("securelyStoredPassword");
usr.Save();usr.Dispose();
ctx.Dispose();