我已经设置了一个ADAM实例并添加了一些测试用户.从c#我可以使用Windows帐户绑定到ADAM,但我无法使用其中一个ADAM用户进行绑定.(我可以成功绑定ldp中的adam用户)我确保通过将msDS-UserAccountDisabled属性设置为false来启用用户.当我与我的Windows帐户绑定时,我可以成功搜索并恢复ADAM用户的属性,但我仍在努力验证它们,当我尝试使用ADAM用户帐户绑定时,我收到错误:
错误:System.Runtime.InteropServices.COMException(0x8007052E):登录失败:未知的用户名或密码错误.在System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
这是我正在使用的代码:
string userName = txtUserName.Text;
string password = txtPassword.Text;
string ADConnectionString = "LDAP://localhost:389/CN=sandbox,DC=ITOrg";
DirectoryEntry entry = new DirectoryEntry(ADConnectionString);
entry.Username = "myComputer\\Administrator";
entry.Password = "myPassword";
try
{
DirectorySearcher searcher = new DirectorySearcher(entry);
searcher.Filter = "(&(objectClass=user)(CN=" + userName + "))";
SearchResultCollection result = searcher.FindAll();
if (result.Count > 0)
{
//bind with simple bind
using (DirectoryEntry de = new DirectoryEntry(result[0].Path, userName, password,AuthenticationTypes.None))
{
if (de.Guid != null) // this is the line where it dies
{
Label1.Text = "Successfully authenticated"; …
Run Code Online (Sandbox Code Playgroud) 我们的用户存储是名为eDirectory的LDAP服务器.如何使用System.DirectoryServices.Protocols更改用户密码?
使用 System.DirectoryServices,可以通过这种方式获得最高提交的USN:
using(DirectoryEntry entry = new DirectoryEntry("LDAP://servername:636/RootDSE"))
{
var usn = entry.Properties["highestCommittedUSN"].Value;
}
Run Code Online (Sandbox Code Playgroud)
但是,我需要使用 System.DirectoryServices.Protocols 从远程 ADLDS 获取此信息,它不利用 ADSI。以下是我尝试执行的操作的简化代码示例:
using(LdapConnection connection = GetWin32LdapConnection())
{
var filter = "(&(highestCommittedUSN=*))";
var searchRequest = new SearchRequest("RootDSE", filter, SearchScope.Subtree, "highestCommittedUSN");
var response = connection.SendRequest(searchRequest) as SearchResponse;
var usn = response.Entries[0].Attributes["highestCommittedUSN"][0];
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,这会引发“DirectoryOperationException:专有名称包含无效语法”。起初我认为 GetWin32LdapConnection() 可能有问题,但该代码在许多其他地方被调用以连接到目录并且永远不会出错。
有任何想法吗?
我正在尝试连接到不同林中的 Active Directory 域 (W2K8R2 DC)。为此,我将凭据传递到以下 DirectoryEntry 构造函数中:
DirectoryEntry(string path, string username, string password, AuthenticationTypes authenticationType)
Run Code Online (Sandbox Code Playgroud)
这一切都很好。不过,我想做的是以某种方式保留连接,并在对 AD 的所有调用中重复使用它,这样我就不需要重复传递凭据。这有可能吗?
谢谢!
是否可以使用员工编号作为查询词从 Active Directory 获取用户的电子邮件?
我正在使用 C#System.DirectoryServices
并且有点迷茫。我公司以前的开发人员正在使用此流程,但他有一封电子邮件,正在查询员工编号。我已将其更改为我认为应该的样子,但说实话,我不太了解代码。
我的代码有问题吗?每次我运行它时,我都会收到一个空引用错误DirectoryEntry up_user =
。我认为这是因为前一行没有得到任何实体。
另外,是否有关于此主题的任何好的文档?我到处看,帖子都是 2011 年或 2013 年的。
我有以下几点:
try
{
string email = string.Empty;
ContextType authenticationType = ContextType.Domain;
PrincipalContext principalContext = new PrincipalContext(authenticationType, "MATRIC");
UserPrincipal userPrincipal = null;
userPrincipal = UserPrincipal.FindByIdentity(principalContext, empnum);
DirectoryEntry up_User = (DirectoryEntry)userPrincipal.GetUnderlyingObject();
DirectorySearcher deSearch = new DirectorySearcher(up_User);
SearchResultCollection results = deSearch.FindAll();
if (results != null && results.Count > 0)
{
ResultPropertyCollection rpc = results[0].Properties;
foreach (string rp in rpc.PropertyNames)
{
if (rp == "mail")
{ …
Run Code Online (Sandbox Code Playgroud)