AD活动目录操作类-示例

用前面那个AD活动目录操作类做一些简单的示例
http://www.cnblogs.com/yangboshan/archive/2007/07/25/830747.html
登陆的时候根据域帐户的名称和密码来验证
页面上有两个TextBox,分别为txtName和txtPass。一个登陆按钮Button1
在Button1的Click事件中写上如下代码:
None.gif   Dim  userName  As   String   =   Me .txtName.Text
None.gif 
Dim  passWord  As   String   =   Me .txtPass.Text
None.gif    Dim  result  As   Integer
None.gif            ADHelper.UserName 
=  userName
None.gif            ADHelper.PassWord 
=  passWord

调用操作类的Login函数
None.gif   result  =  ADHelper.Login(userName, passWord)

根据返回值来做不同操作
None.gif If  (result  =   0 Then
None.gif                               Session(
" name " =  userName
None.gif                
Dim  email  As   String   =  ADHelper.GetProperty(ADHelper.test(userName),  " Mail " )
None.gif                
Dim  telephone  As   String   =  ADHelper.GetProperty(ADHelper.test(userName),  " telephoneNumber " )
None.gif                
Dim  office  As   String   =  ADHelper.GetProperty(ADHelper.test(userName),  " physicalDeliveryOfficeName " )
None.gif                
Dim  department  As   String   =  ADHelper.GetProperty(ADHelper.test(userName),  " Department " )
None.gif                
Dim  position  As   String   =  ADHelper.GetProperty(ADHelper.test(userName),  " Title " )
None.gif                Session(
" pos " =  position
None.gif                Session(
" dept " =  department
None.gif                Session(
" office " =  office
None.gif                Session(
" email " =  email
None.gif                Session(
" telephone " =  telephone
None.gif                
Me .Label6.Text  =   " Login successfully "
None.gif                
Me .Label6.ForeColor  =  Drawing.Color.Green
None.gif                
Me .Button1.Text  =   " Log_out "
None.gif                         
Else
None.gif                
Me .Label6.Text  =   " Login fail "
None.gif                
Me .Label6.ForeColor  =  Drawing.Color.Red
None.gif            
End   If
当result返回0时,表示验证用户成功,并把帐户的一些常用属性写进Session
下面是操作类中的Enum。
ExpandedBlockStart.gif ContractedBlock.gif   Public   Enum LoginResult Enum LoginResult
InBlock.gif
InBlock.gif        LOGIN_OK 
= 0
InBlock.gif        LOGIN_USER_DOESNT_EXIST
InBlock.gif        LOGIN_USER_ACCOUNT_INACTIVE
ExpandedBlockEnd.gif    
End Enum
操作类中ADPath的值是放在配置文件中的,其中wl.com就是域控的名称。
None.gif < appSettings >
None.gif    
< add  key ="ADPath"  value ="LDAP://wl.com" />
None.gif
</ appSettings >
在上面取得用户的属性是根据用户名和密码的。
如果只根据用户名取得属性可以如下面这样写:
use是用户名
None.gif Dim  mailAddress  as   String =  ADHelper.GetProperty(ADHelper.nopassword(use),  " Mail " )
上面这句代码就是根据用户名取得Mail属性的值

转载于:https://www.cnblogs.com/yangboshan/archive/2007/07/30/836089.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值