我正在開發的項目將與客戶Active Directory集成以驗證用戶身份。我一直在嘗試編寫一些代碼來檢索用戶密碼,並且我知道Active Directory只會通過端口636上的SSL連接公開相關屬性。C#:如何在啓用SSL的情況下連接到Active Directory?
以下代碼在不使用SSL的情況下以編程方式進行連接,但後來我可以「看不到密碼屬性:
static void Main(string[] args)
{
DirectoryEntry entry = new DirectoryEntry(@"LDAP://<IP>/CN=LDAP Test,CN=Users,DC=customer,DC=com");
entry.AuthenticationType = AuthenticationTypes.None;
entry.Username = "CN=LDAP Test,CN=Users,DC=customer,DC=com";
entry.Password = "<password>";
if (entry != null)
{
foreach (Object propName in entry.Properties.PropertyNames)
{
Console.WriteLine((String)propName);
}
}
}
當我改變使用SSL我得到一個異常說明代碼;未知錯誤(0x80005000)」。
我在託管Active Directory的服務器上啓用了SSL,在同一臺服務器上安裝了Microsoft CA,並從CA獲得了證書。
我可以使用Apache Directory Studio通過SSL連接到Active Directory,但不顯示密碼屬性。
下面的代碼顯示了我一直在嘗試使用使用SSL連接:
static void Main(string[] args)
{
DirectoryEntry entry = new DirectoryEntry(@"LDAPS://<IP>:636/CN=LDAP Test,CN=Users,DC=customer,DC=com");
entry.AuthenticationType = AuthenticationTypes.SecureSocketsLayer;
entry.Username = "CN=LDAP Test,CN=Users,DC=customer,DC=com";
entry.Password = "<password>";
if (entry != null)
{
foreach (Object propName in entry.Properties.PropertyNames)
{
Console.WriteLine((String)propName);
}
}
}
我不知道去哪裏這一點,一些援助將不勝感激。
相關:http://stackoverflow.com/questions/287100/setting-up-ssl-in-active-directory-how-to/291826 – 2009-08-04 18:04:57
的ADAM常見問題是在這裏:HTTP:/ /www.microsoft.com/windowsserver2003/adam/ADAMfaq.mspx#EOD – 2009-08-04 18:13:48