列出域中所有用户的代码

using System;
None.gif
using System.Data;
None.gif
using System.Configuration;
None.gif
using System.Collections;
None.gif
using System.Web;
None.gif
using System.Web.Security;
None.gif
using System.Web.UI;
None.gif
using System.Web.UI.WebControls;
None.gif
using System.Web.UI.WebControls.WebParts;
None.gif
using System.Web.UI.HtmlControls;
None.gif
using System.DirectoryServices;
None.gif
None.gif
namespace WebAppLDAP
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
public partial class _Default : System.Web.UI.Page
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
protected void Page_Load(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//ListAllUser();
InBlock.gif
             showUser();
ExpandedSubBlockEnd.gif         }

InBlock.gif        
protected void showUser()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif             DirectoryEntry entry
= new DirectoryEntry("LDAP://ABC.COM.CN");
InBlock.gif             System.DirectoryServices.DirectorySearcher mySearcher
= new System.DirectoryServices.DirectorySearcher(entry);
InBlock.gif
InBlock.gif             mySearcher.Filter
= "(&(objectClass=user)(objectCategory=person))";
InBlock.gif
InBlock.gif             mySearcher.PropertiesToLoad.Add(
"name"); //用户名
InBlock.gif
             mySearcher.PropertiesToLoad.Add("samaccountname"); //用户帐号
InBlock.gif

InBlock.gif             SearchResultCollection resultCol
= mySearcher.FindAll();
InBlock.gif
InBlock.gif            
foreach (SearchResult result in resultCol)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                 ResultPropertyCollection props
= result.Properties;
InBlock.gif
InBlock.gif                
foreach (string propName in props.PropertyNames)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
//Response.Write(props[propName][0] + "<BR>");
InBlock.gif
                    if (propName == "name")
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                         Response.Write(props[propName][
0] + "<BR>");
ExpandedSubBlockEnd.gif                     }

InBlock.gif                    
if (propName == "samaccountname")
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                         Response.Write(props[propName][
0] + "<BR><BR>");
ExpandedSubBlockEnd.gif                     }

ExpandedSubBlockEnd.gif                 }

ExpandedSubBlockEnd.gif             }

ExpandedSubBlockEnd.gif         }

ExpandedSubBlockEnd.gif     }

ExpandedBlockEnd.gif}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值