就是一般操作AD时会这样写:
DirectoryEntry de = new DirectoryEntry();
de.Path = "LDAP://WynnZheng.local/CN=DT, OU=MusicMan, DC=WynnZheng, DC=local";
但我现在不知道LDAP后面的东西,我要怎么获得呢?
DirectoryEntry de = new DirectoryEntry();
de.Path = "LDAP://WynnZheng.local/CN=DT, OU=MusicMan, DC=WynnZheng, DC=local";
但我现在不知道LDAP后面的东西,我要怎么获得呢?
就是C#程序与AD集成,这个程序需要对用户进行验证,当程序在域环境中使用时,就直接用域的账号密码验证。
private string GetCurrentFullName()
{
string DomainName = System.Environment.UserDomainName;
string AccountName = System.Environment.UserName.ToLower();
DirectoryEntry de = new DirectoryEntry("LDAP://" + DomainName);
DirectorySearcher ds = new DirectorySearcher(de);
ds.Filter = ("(objectClass=user)");
foreach (SearchResult sr in ds.FindAll())
{
string fullName = sr.GetDirectoryEntry().Name.ToString();
if (sr.GetDirectoryEntry().Properties["samaccountname"].Value.ToString().ToLower() == AccountName)
{
return fullName.Substring(3, fullName.Length-3);
}
}
return "";
}