.Net 可以使用 DirectoryEntry 連接 Active Directory ,假如有個管理後台網頁,此時就可以透過 Active Directory 認證登入後台。
範例程式碼如下:
string ActiveDirectoryName = "AD網址或者IP"; string UserName = "帳號"; string UserPwd = "密碼"; DirectoryEntry de = new DirectoryEntry("LDAP://" + ActiveDirectoryName, UserName, UserPwd); PropertyCollection pc = de.Properties; if (pc == null) { Response.Write("登入失敗"); } else { Response.Write("登入成功<br><br>"); //列出相關參數 foreach (string k in pc.PropertyNames) { try { Response.Write(k + " = " + pc[k][0] + "<br>"); } catch { } } }