如何使用LdapConnection 类 (1)链接 Ldap服务器
2009-08-31 12:57
381 查看
C#提供了 LdapConnection 类用于连接Microsoft Active Directory 域服务或 LDAP 服务器的 TCP/IP 或 UDP LDAP 连接。
下面是连接 Ldap的连接方法和大家分享下:
1
static LdapConnection ldapConnection;
2
static string ldapServer;
3
static NetworkCredential credential;
4
static string targetOU;
5
static string pwd;
6
public void LdapBind()
7
{
8
ldapServer = "172.18.69.204:389";
9
targetOU = "cn=Manager,dc=tst,dc=com";
10
pwd = "000000";
11
12
//credential = new NetworkCredential(String.Empty, String.Empty);
13
credential = new NetworkCredential(targetOU, pwd);
14
15
16
string dn = "";
17
18
//ldapConnection = new LdapConnection(new LdapDirectoryIdentifier(ldapServer));
19
//ldapConnection.SessionOptions.ProtocolVersion = 3;//Ldap协议版本
20
//ldapConnection.AuthType = AuthType.Anonymous;//不传递密码进行连接
21
22
ldapConnection = new LdapConnection(ldapServer);
23
ldapConnection.AuthType = AuthType.Basic;
24
ldapConnection.Credential = credential;
25
26
try
27
{
28
Console.WriteLine("链接
.");
29
ldapConnection.Bind();
30
Console.WriteLine("链接成功");
31
32
}
33
catch (Exception ee)
34
{
35
Console.WriteLine(ee.Message);
36
}
37
38
39
ldapConnection.Dispose();
40
41
}
注意
1、如果我们使用ldapConnection.AuthType = AuthType.Anonymous; 的认证方式,就一定要让Dn与Pwd为空,实现匿名认证方式,如:
credential = new NetworkCredential(String.Empty, String.Empty);
2、使用c#连接Ldap服务器,还可以使用 Novell公司的Novell.Directory.Ldap来实现。
下面是连接 Ldap的连接方法和大家分享下:
1
static LdapConnection ldapConnection;
2
static string ldapServer;
3
static NetworkCredential credential;
4
static string targetOU;
5
static string pwd;
6
public void LdapBind()
7
{
8
ldapServer = "172.18.69.204:389";
9
targetOU = "cn=Manager,dc=tst,dc=com";
10
pwd = "000000";
11
12
//credential = new NetworkCredential(String.Empty, String.Empty);
13
credential = new NetworkCredential(targetOU, pwd);
14
15
16
string dn = "";
17
18
//ldapConnection = new LdapConnection(new LdapDirectoryIdentifier(ldapServer));
19
//ldapConnection.SessionOptions.ProtocolVersion = 3;//Ldap协议版本
20
//ldapConnection.AuthType = AuthType.Anonymous;//不传递密码进行连接
21
22
ldapConnection = new LdapConnection(ldapServer);
23
ldapConnection.AuthType = AuthType.Basic;
24
ldapConnection.Credential = credential;
25
26
try
27
{
28
Console.WriteLine("链接
.");
29
ldapConnection.Bind();
30
Console.WriteLine("链接成功");
31
32
}
33
catch (Exception ee)
34
{
35
Console.WriteLine(ee.Message);
36
}
37
38
39
ldapConnection.Dispose();
40
41
}
注意
1、如果我们使用ldapConnection.AuthType = AuthType.Anonymous; 的认证方式,就一定要让Dn与Pwd为空,实现匿名认证方式,如:
credential = new NetworkCredential(String.Empty, String.Empty);
2、使用c#连接Ldap服务器,还可以使用 Novell公司的Novell.Directory.Ldap来实现。
相关文章推荐
- 如何使用LdapConnection 类链接 Ldap服务器
- 如何使用LdapConnection 类 (1)链接 Ldap服务器
- 如何通过 SQL Server 链接服务器和分布式查询使用 Excel
- 如何通过 SQL Server 链接服务器和分布式查询使用 Excel
- 如何通过 SQL Server 链接服务器和分布式查询使用 Excel
- 如何解决使用分布式事务操作链接服务器时出现的7391错误
- 如何通过 SQL Server 链接服务器和分布式查询使用 Excel
- 如何使用SQL Server链接服务器访问DB2 Server
- linux -- 如何查看服务器所使用的linux版本
- 如何使用秘钥链接github
- 如何同时启动多个Tomcat服务器(转)--fedora下验证也可以使用
- 如何:使用自定义函数对 ASP.NET 服务器控件进行验证
- 如何创建redhat的yum的本地源和使用163服务器的源
- 如何使用Tomcat配置本地服务器
- mondrian 如何使用xml存储olap服务器的元数据
- 如何使用R语言链接数据库并对数据库中的表进行查询操作
- 如何使用WampServer搭建PHP服务器
- Linux如何查看服务器的并发数? 使用netstat命令查看并发连接数
- 如何使用Navicat Lite链接Oracle数据库
- 如何使用windows域服务器