在asp.net中,我用c#进行AD操作,添加用户

本文介绍如何在ASP.NET环境中使用C#编程语言进行Active Directory(AD)操作,特别是添加用户到AD的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

主  题:
关于 AD ,高手请进,在线等待
在asp.net中,我用c#进行AD操作,添加用户,我怎么才能列举本域中下面的所有用户,包括Users,和自己建立的组织单位,请举例,谢谢
回复人: yxrj() ( ) 信誉:105 2002-07-23 09:38:35Z 得分:50
?
DirectoryEntry objDE;
//列出用户
objDE=new DirectoryEntry("LDAP://yourserver/cn=users,dc=xxx,dc=com","Administrator","pwd",System.DirectoryServices.AuthenticationTypes.ServerBind);
foreach(DirectoryEntry ch in objDE.Children)
   Response.Write(ch.Path+"
"+ch.SchemaClassName+"

"); //建用户 DirectoryEntry objDE1=objDE.Children.Add("cn=newtest","user"); objDE1.Invoke("Put",new Object[2] {"givenName","newtest"}); objDE1.Invoke("Put",new Object[2] {"samAccountName","newtest"}); objDE1.Invoke("Put",new Object[2] {"userPrincipalName","newtest"}); objDE1.Invoke("Put",new Object[2] {"UserAccountControl","512"}); objDE1.CommitChanges(); objDE1.Invoke("ChangePassword",new Object[2] {"","pwd"}); objDE1.CommitChanges();
Top
回复人: yxrj() ( ) 信誉:105 2002-07-23 10:15:29Z 得分:50
?
如果要查找所有容器下的user,用DirectorySearcher 

DirectoryEntry objDE=new DirectoryEntry("LDAP://yourserver","Administrator","pwd",System.DirectoryServices.AuthenticationTypes.ServerBind);
System.DirectoryServices.DirectorySearcher mySearcher = new System.DirectoryServices.DirectorySearcher(objDE);
mySearcher.Filter = ("(objectClass=user)");
foreach(System.DirectoryServices.SearchResult resEnt in mySearcher.FindAll())
    {
        Response.Write( resEnt.Path+"
         
"); }
Top
回复人: yxrj() ( ) 信誉:105 2002-07-23 10:22:49Z 得分:0
?
如果要查找所有容器下的user,用DirectorySearcher 

DirectoryEntry objDE=new DirectoryEntry("LDAP://yourserver","Administrator","pwd",System.DirectoryServices.AuthenticationTypes.ServerBind);
System.DirectoryServices.DirectorySearcher mySearcher = new System.DirectoryServices.DirectorySearcher(objDE);
mySearcher.Filter = ("(objectClass=user)");
foreach(System.DirectoryServices.SearchResult resEnt in mySearcher.FindAll())
{
        Response.Write( resEnt.Path+"
         
"); }
Top
回复人: Richard2001(Richard) ( ) 信誉:98 2002-07-23 10:30:27Z 得分:0
?
我也试试。
Top
回复人: cuiaimin(Shadow) ( ) 信誉:99 2002-07-23 10:54:37Z 得分:0
?
谢谢yxrj
Top
回复人: ameng_2002(flyfox) ( ) 信誉:105 2002-07-23 11:09:33Z 得分:0
?
gz
Top
回复人: ketao_78(树欲静而风不止) ( ) 信誉:101 2002-07-23 14:20:45Z 得分:0
?
哇,这个可真够厉害
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值