我正在尝试诊断客户端站点上运行的服务器应用程序的问题。所述应用程序针对广告环境中的域控制器认证用户凭证。我们看到的行为是定期没有用户可以通过服务器进行身份验证。
我们基本上把失败追溯到“绑定”失败。为了进一步诊断这个问题,我构建了一个超级简单的工具,它执行两种类型的绑定:一种使用LDAP服务器绑定,另一种使用WinNT绑定。我们的服务器应用程序只进行LDAP绑定,但是为了添加控件,我加入了WinNT绑定。
public static void DoWinNTBind(string domain, string login, string password)
{
Logger.Log("Starting WinNT Bind to {0}",domain);
try
{
var serverPath = String.Format("WinNT://{0}",domain);
Logger.Log("Creating DirectoryEntry object for {0} on domain {1}", login, serverPath);
using (DirectoryEntry de = new DirectoryEntry(serverPath, login, password, AuthenticationTypes.Secure | AuthenticationTypes.Sealing))
{
if (!de.NativeObject.Equals(null))
{
Logger.Log("WinNT Bind Success");
}
else
{
Logger.Log("WinNT Bind Failed");
}
}
}
catch(Exception ex)
{
Logger.Log("{0} occured during WinNT Bind: {1}",ex.GetType().Name,ex.Message);
Logger.Log("Stack: {0}",ex.StackTrace);
}
}
public static void DoLDAPBind(string domain,string login, string password)
{
Logger.Log("Starting LDAP Bind to {0}",domain);
try
{
var serverPath = String.Format("LDAP://{0}",domain);
Logger.Log("Creating DirectoryEntry object for {0} on domain {1}", login, serverPath);
using (DirectoryEntry de = new DirectoryEntry(serverPath, login, password, AuthenticationTypes.Secure | AuthenticationTypes.Sealing))
{
if (!de.NativeObject.Equals(null))
{
Logger.Log("LDAP Bind Success");
}
else
{
Logger.Log("LDAP Bind Failed");
}
}
}
catch(Exception ex)
{
Logger.Log("{0} occured during LDAP Bind: {1}",ex.GetType().Name,ex.Message);
Logger.Log("Stack: {0}",ex.StackTrace);
}
}
如您所见,除了使用System.DirectoryServices.DirectoryEntry连接到DC之外,没有太多代码。
生成的日志文件是(名称和域被屏蔽)。
用户绑定2010年6月29日下午2:52:17:
正在启动LDAP绑定到xxx.xxx
2010年6月29日下午2:52:17:创建
发生DirectoryServicesMexception
未知用户名或错误密码。
2010年6月29日下午2:52:17:堆栈:在
throwIfFail)在
System.DirectoryServices.DirectoryEntry.Bind()
在
System.DirectoryServices.DirectoryEntry.get\u NativeObject()
AdmitOne.Superglue.ActiveDirectoryHelper.DoLDAPBind(字符串
域,字符串登录,字符串密码)
C:\Projects\Galapagos\branchs\Contract\2.0\u SN\u Peer\Src\Tools\Superglue\ActiveDirectoryHelper.cs:行
47 2010年6月29日下午2:52:17:开始
WinNT绑定到xxx.xxx 6/29/2010
域上用户1的对象
WinNT://xxx.xxx 2010年6月29日下午2:52:18:
WinNT绑定成功
所以相同的用户名无法使用LDAP绑定,但是使用WinNT成功了!
在本地的测试环境中,我们看不到这种行为,LDAP和WinNT都没有问题。
我首先询问堆栈,以确保我的绑定代码是正确的。之后,我可能需要重新询问Serverfault,这是询问特定于广告的问题的更合适的地方。