【发布时间】:2012-03-26 05:02:15
【问题描述】:
我使用 System.DirectoryServices 中的类来更改 AD 中的密码。代码如下:
DirectoryEntry _directoryEntry = new DirectoryEntry(ldapPath, user, pwd, AuthenticationTypes.Secure);
public bool ChangePassword(string userPath, string newPassword)
{
try
{
if (userPath != null && _directoryEntry != null)
{
_directoryEntry.Path = userPath;
//Set the password
_directoryEntry.Invoke("SetPassword", new object[] { newPassword });
_directoryEntry.CommitChanges();
return true;
}
}
catch (Exception ex)
{
//Invalid Login or the domain controller is not contactable
throw ex;
}
finally
{
_directoryEntry.Close();
_directoryEntry = null;
}
return false;
}
我在不同的计算机上执行了这些代码。花费的时间从几毫秒到几秒。
为什么在不同的环境中执行相同的代码来更改 AD 中的密码花费不同的时间?我花了很多时间来处理这个问题,但仍然没有结果。谁能告诉我?非常感谢!!!!!!
【问题讨论】:
-
我的第一个想法是:不同机器之间的网络拓扑有区别吗?更改域控制器(例如)上的 AD 密码可能比在远离主机的客户端计算机上执行它所花费的时间要少得多。
-
有的电脑和AD在同一个网段,有的不在。但是如果电脑能快速修改AD密码,它就可以快速修改不同网段的任意AD。所以我认为这可能与网络拓扑无关,而与计算机上的系统环境有关。就像其中一台计算机上的某些服务已启动,但其他服务未启动。但是我找不到任何明显的差异来使某些计算机比其他计算机运行得更快。 @ravuya
标签: c# asp.net .net active-directory