C# 访问AD中用户信息的几个操作
2008-04-18 14:23
309 查看
查找指定的用户,显示其所有属性
public void SearchUser(string userName)
...{
DirectoryEntry deUser = new DirectoryEntry("LDAP://10.99.185.18/DC=zhaijx,DC=cn","codingtaoist","54638");
DirectorySearcher src = new DirectorySearcher(deUser);
src.Filter = "(&(objectClass=user)(SAMAccountName="+userName+"))";
src.SearchRoot = deUser;
src.SearchScope = SearchScope.Subtree;
SearchResult result = src.FindOne();
DirectoryEntry objDirEnt = new DirectoryEntry(result.Path, "codingtaoist","54638", AuthenticationTypes.Secure);
IDictionaryEnumerator e = objDirEnt.Properties.GetEnumerator();
Response.Write("<table>");
while(e.MoveNext())
...{
DisplayOneProperty(objDirEnt,e.Key.ToString());
}
Response.Write("</table>");
}
public void DisplayOneProperty(DirectoryEntry de , string PropertyName)
...{
if (de.Properties.Contains(PropertyName))
...{
string myvalue= de.Properties[PropertyName].Value.ToString();
Response.Write("<tr>");
Response.Write("<td>");
Response.Write(PropertyName);
Response.Write("</td>");
Response.Write("<td>");
Response.Write(myvalue);
Response.Write("</td>");
Response.Write("</tr>");
}
}
判断用户是否禁用
private bool isDisable(DirectoryEntry de)
...{
if(de.Properties.Contains("UserAccountControl"))
...{
string myvalue= de.Properties["UserAccountControl"].Value.ToString();
if(myvalue=="514")
...{
return true;
};
}
return false;
}
public void SearchUser(string userName)
...{
DirectoryEntry deUser = new DirectoryEntry("LDAP://10.99.185.18/DC=zhaijx,DC=cn","codingtaoist","54638");
DirectorySearcher src = new DirectorySearcher(deUser);
src.Filter = "(&(objectClass=user)(SAMAccountName="+userName+"))";
src.SearchRoot = deUser;
src.SearchScope = SearchScope.Subtree;
SearchResult result = src.FindOne();
DirectoryEntry objDirEnt = new DirectoryEntry(result.Path, "codingtaoist","54638", AuthenticationTypes.Secure);
IDictionaryEnumerator e = objDirEnt.Properties.GetEnumerator();
Response.Write("<table>");
while(e.MoveNext())
...{
DisplayOneProperty(objDirEnt,e.Key.ToString());
}
Response.Write("</table>");
}
public void DisplayOneProperty(DirectoryEntry de , string PropertyName)
...{
if (de.Properties.Contains(PropertyName))
...{
string myvalue= de.Properties[PropertyName].Value.ToString();
Response.Write("<tr>");
Response.Write("<td>");
Response.Write(PropertyName);
Response.Write("</td>");
Response.Write("<td>");
Response.Write(myvalue);
Response.Write("</td>");
Response.Write("</tr>");
}
}
判断用户是否禁用
private bool isDisable(DirectoryEntry de)
...{
if(de.Properties.Contains("UserAccountControl"))
...{
string myvalue= de.Properties["UserAccountControl"].Value.ToString();
if(myvalue=="514")
...{
return true;
};
}
return false;
}
相关文章推荐
- 在C#中访问AD用户信息的示例操作
- AD帐户操作C#示例代码(一)——导入用户信息
- C# 获取 域(AD) 用户信息
- C# 获取AD组中的用户信息
- ASP.NET MVC 操作AD 获取域服务器当前用户姓名和OU信息
- C#获取AD用户信息
- C# 获取 域(AD) 用户信息
- AD用户属性&C#操作实例
- C# AD(Active Directory)域信息同步,组织单位、用户等信息查询
- 用struts,某一个用户已登录,我要在几个页面上用到该用户的一些信息比如姓名,怎样做呢,是不是要访问数据库?
- C#以操作数据库方式访问EXCEL文件的几个常见问题及解决方法
- C#获取AD用户信息
- C#获取AD用户信息
- C# 获取AD用户信息
- java以及C#获取AD域上用户信息
- C# AD(Active Directory)域信息同步,组织单位、用户等信息查询
- C#获取AD用户信息
- C# 多用户操作不允许所请求的注册表访问权
- C#获取AD域中计算机和用户的信息
- (证实可用)C#获取AD所有的用户信息,比如登录名,邮件名,属于组织,名字