C# 更新广告用户信息
我在更新Active Directory数据库中的用户信息时遇到问题 当我运行以下代码时,会出现此错误: 指定的目录服务属性或值不存在 问题在于它用于保存信息的路径如下:C# 更新广告用户信息,c#,asp.net-mvc,c#-4.0,active-directory,C#,Asp.net Mvc,C# 4.0,Active Directory,我在更新Active Directory数据库中的用户信息时遇到问题 当我运行以下代码时,会出现此错误: 指定的目录服务属性或值不存在 问题在于它用于保存信息的路径如下: CN=AD Test,OU=Container Name,DC=us,DC=flg,DC=int Ad Test是我试图更新的广告中的用户名 我认为应该是: CN=Ad Test,OU=Container Name, OU=Server Name,DC=us,DC=flg,DC=int 我是新的目录服务,所以我将非常感谢任
CN=AD Test,OU=Container Name,DC=us,DC=flg,DC=int
Ad Test
是我试图更新的广告中的用户名
我认为应该是:
CN=Ad Test,OU=Container Name, OU=Server Name,DC=us,DC=flg,DC=int
我是新的目录服务,所以我将非常感谢任何帮助,找出为什么我不能更新。。。先谢谢你
public bool UpdateActiveDirectory(string LdapServerName, string CustId, Employee SQLresult)
{
try
{
DirectoryEntry rootEntry = new DirectoryEntry("LDAP://" + LdapServerName, "usrename", "password", AuthenticationTypes.Secure);
DirectorySearcher searcher = new DirectorySearcher(rootEntry);
searcher.Filter = "(sAMAccountName=" + SQLresult.LogonNT + ")";
searcher.PropertiesToLoad.Add("title");
searcher.PropertiesToLoad.Add("street");
searcher.PropertiesToLoad.Add("1");
searcher.PropertiesToLoad.Add("st");
searcher.PropertiesToLoad.Add("postalCode");
searcher.PropertiesToLoad.Add("department");
searcher.PropertiesToLoad.Add("mail");
searcher.PropertiesToLoad.Add("manager");
searcher.PropertiesToLoad.Add("telephoneNumber");
SearchResult result = searcher.FindOne();
if (result != null)
{
// create new object from search result
DirectoryEntry entryToUpdate = result.GetDirectoryEntry();
entryToUpdate.Properties["title"].Value = SQLresult.Title;
entryToUpdate.Properties["street"].Value = SQLresult.Address;
entryToUpdate.Properties["1"].Value = SQLresult.City;
entryToUpdate.Properties["st"].Value = SQLresult.State;
entryToUpdate.Properties["postalCode"].Value = SQLresult.ZipCode;
entryToUpdate.Properties["department"].Value = SQLresult.Department;
entryToUpdate.Properties["mail"].Value = SQLresult.EMailID;
entryToUpdate.Properties["manager"].Value = SQLresult.ManagerName;
entryToUpdate.Properties["telephoneNumber"].Value = SQLresult.Phone;
entryToUpdate.CommitChanges();
Console.WriteLine("User Updated");
}
else
{
Console.WriteLine("User not found!");
}
}
catch (Exception e)
{
Console.WriteLine("Exception caught:\n\n" + e.ToString());
}
return true;
}
也许只是打字错误
您尝试更新的第三个属性:
entryToUpdate.Properties["1"].Value = SQLresult.City;
里面有一个(1
)吗?它应该是一个小L(L
)
另外:经理的姓名必须是经理的可分辨名称-整体名称
CN=Manager,CN=Ad Test,OU=Container Name, OU=Server Name,DC=us,DC=flg,DC=int
不仅仅是名字本身
如果这没有任何帮助-只需回到老派调试技术:
- 只更新一个属性;如果失败-->这就是您的问题案例-找出问题的原因李>
- 如果有效:取消注释第二个属性并再次运行
->重复一遍又一遍,直到你发现你的罪魁祸首可能只是一个打字错误?您尝试更新的第三个属性:
entryToUpdate.Properties[“1”].Value=SQLresult.City代码>-里面有一个(1
)吗?它应该是一个小的L
(L
)。另外:管理器的名称必须是管理器的可分辨名称-整个CN=manager,CN=Ad Test,OU=Container name,OU=Server name,DC=us,DC=flg,DC=int
thing—不仅仅是名称本身。如果这没有任何帮助—只需回到老派的调试技术:只更新一个属性—如果失败-->这是您的问题案例—找出问题的原因。如果有效:取消对第二个属性的注释并再次运行->反复重复,直到找到罪犯谢谢marc\s。。。解决了这个问题。。。当我尝试提交更改时,我得到了一个不同的错误,它说:“拒绝访问”。我以为它会使用我最初传入的凭据。在提交期间我将如何使用它们?可能您正在使用的凭据只允许从Active Directory读取…用户帐户没有正确的保存权限。谢谢你的帮助。。。