vps*_*vps 3 ldap active-directory ldap-query vb.net-2010
我正在使用vb.net,我想检查Active Directory中是否存在特定用户.如果是,我想显示特定用户的详细信息.怎么做?
用户登录凭据通过文本框控件传递
我的代码:
Dim de As DirectoryEntry = GetDirectoryEntry()
Dim ds As DirectorySearcher = New DirectorySearcher(de)
ds.Filter = "(&(objectClass=txt1.text))"
' Use the FindAll method to return objects to SearchResultCollection.
results = ds.FindAll()
Public Shared Function GetDirectoryEntry() As DirectoryEntry
Dim dirEntry As DirectoryEntry = New DirectoryEntry()
dirEntry.Path = "LDAP://ss.in:389/CN=Schema,CN=Configuration,DC=ss,DC=in"
dirEntry.Username = "ss.in\ssldap"
dirEntry.Password = "ss@123"
'Dim searcher As New DirectorySearcher
'searcher.SearchRoot = dirEntry
Return dirEntry
End Function
Run Code Online (Sandbox Code Playgroud)
我传递密码的地方.这段代码是否正确?我是AD的新手.请帮我这样做?
如果您使用的是.NET 3.5及更高版本,则应该查看System.DirectoryServices.AccountManagement(S.DS.AM)命名空间.在这里阅读所有相关内容:
基本上,您可以定义域上下文并轻松查找AD中的用户和/或组:
// set up domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
// find a user
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, "SomeUserName");
if(user != null)
{
// your user exists - do something here....
}
else
{
// your user in question does *not* exist - do something else....
}
Run Code Online (Sandbox Code Playgroud)
或者在VB.NET中:
' set up domain context
Dim ctx As New PrincipalContext(ContextType.Domain)
' find a user
Dim user As UserPrincipal = UserPrincipal.FindByIdentity(ctx, "SomeUserName")
If user IsNot Nothing Then
' your user exists - do something here....
Else
' your user in question does *not* exist - do something else....
End If
Run Code Online (Sandbox Code Playgroud)
新的S.DS.AM使得在AD中与用户和群组玩游戏变得非常容易!
| 归档时间: |
|
| 查看次数: |
10144 次 |
| 最近记录: |